abhimanipal 91 Master Poster

1. Take the input from the user into a string called input
2. Use string length to go to the end of the string.
3a. Start iterating towards the start of the string. When you hit the space char, then stop. Store the chars that you iterated over into a temp string.
b. Reverse the temp string and then store the output in the output string
4. Repeat step 3 till you cover the entire input string

abhimanipal 91 Master Poster

If you want to make your own string comparison function

1. If length of string 1 is not equal to string 2 then, strings are not identical
2. for i:0, to strlen, check if the str1 == str2. If they are not equal then break out of the loop

abhimanipal 91 Master Poster

For those starting out to develop apps for iPhone check out the Stanford University Lectures on the same. The lectures are pretty descriptive and contain lots of examples.
This the link for the 1st lecture. You can find out the remaining lectures from the related videos tab

abhimanipal 91 Master Poster

I dont know which more worse. Your ignorance about C or your stubbornness

abhimanipal 91 Master Poster

Have you heard of a little known website called as google.... Try it out.... You might like it
Here is what I found in just 0.23 seconds in this website

http://www.codeproject.com/KB/audio-video/madlldlib.aspx

abhimanipal 91 Master Poster

According to your above post the function set_number_people is not defined to be a part of any class but yet when you call it, you use an object to call the function

abhimanipal 91 Master Poster

Yes you can .... But you will have to figure out what are the ASCI values of the arrow keys
In future start a separate thread for your questions. Even if you feel that your question is related to the current discussion

abhimanipal 91 Master Poster

Probably you could use a switch statement ????

http://msdn.microsoft.com/en-us/library/66k51h7a%28VS.80%29.aspx

abhimanipal 91 Master Poster

@nbaztec

Are you actually recommending gets over fgets ?

abhimanipal 91 Master Poster

Open file 1
Open file 2
Read a string of n chars from file1 into array1
Read a string of n chars from file 2 into aray2

Compare array1 and array2. You will have to ignore spaces and new lines when you are trying to comapre

abhimanipal 91 Master Poster

Logically Incorrect
void main as opposed to int main
Unnecessary use of goto

Aia commented: GOTO jail, don't collect $200. Where's that free jail card when needed? ;) +9
abhimanipal 91 Master Poster

Use pointer to pointer for passing the FILE pointer

Also you dont need the if condition on line 92.
After the while loop just use the 2 for loops
for(k=l;k<=mid;k++)
{}
for(k=j;k<=high;k++)
{}

that it. If you cant understand why this is sufficient, work it out on a paper and pencil. Also print the array at the end of the sort function. So you can see how the array is getting sorted. So if there is a bug it will be easier for you.
If you still cant debug, paste the input to the sort function and its final output here

abhimanipal 91 Master Poster

There is a logical error in your code. Check to see what code I have written and you will spot the error.

mult1=1;
for(i=n;i<=m;i++) //loop till the m
{
     mult=1; 
     for(j=1;j<=i;j++)// for factorial
     {
        mult=mult*j;
     }
     mult1=mult1*mult;
}

PS: Avoid using scanf. It has lots of hidden problems. Shift to fgets instead

abhimanipal 91 Master Poster

What exactly is the problem ? When you say nothing is happening its really not that descriptive ....
Are you able to open the input/output files ?
Are you getting garbage o/p ?
Are you getting compile time/ run time errors ?

The more detail that you give about the error, the faster it will get solved

abhimanipal 91 Master Poster

What have you got so far ?
Are you a CS student ?And you are trying to get other people to do your programming assignment

abhimanipal 91 Master Poster

Yes I think you are correct. But I advise you to cement your understanding by using some example.
For instance if I have the data 10,20,15, how will the code handle it ?

abhimanipal 91 Master Poster

Also this branch is totally wrong-

/* invalid prime factor */
    else {
      if(d == 2) d = 3;
      else d += 2;
    }

this code will fail after prime P=7 -> 7+2 = 9, but 9 is not prime number, instead after 7, next prime factor should be 11.
http://en.wikipedia.org/wiki/Prime_number
So this approach is BAD. Instead you must save prime numbers into some array kind of

int primes[N] = {2, 3, 5, 7, 11, 13, 17,/* until N*/};

then in invalid prime factor branch just move to next prime factor in primes array.

I dont think what you are saying is correct. The algorithm used by westsider is correct.
Yes after 7 the code will indeed produce 9 and 9 is not a prime number. But the input number will never be divisible by 9. So if the input is 27, the code will divide it first by 3 to get 9 and then again by 3 to get 3 and then again by 3. No problems here.
Similarly if the input is 34. The code divides the input first by 2 to get 17. Then it will iterate through 3,5,7,9,11,13,15 none of which divides 17. Only 17 divides 17.No problems here as well.
The method given by you is wrong. You want him to save the prime numbers in an array. So if the input number is 100, you want all the prime numbers from 1-100 to be stored in an array. But how …

tux4life commented: Exactly. +8
abhimanipal 91 Master Poster

If your code is huge then break it into functions
If you have to pass some parameters to the functions, passing them by pointers has an advantage that you can manipulate the value of the string inside the function

Does this answer your question ?If not phrase it differently. As of now its not making any sense at all

mr.confused! commented: not a smart ass! +1
abhimanipal 91 Master Poster
//put meshok1 to gumareli_1, meshok2 to gumareli_2 and then plus it 
//using atoi functions ok?
//could you?
//don't forget to type discription plz
//and if you want add me to google friend(zz follow) list "Mikael Arakelyan"
}

No.....
But tell you what here is an example of how to use strtok function http://www.cplusplus.com/reference/clibrary/cstring/strtok/

So if the user can enter strings which just have 2 operands then the code is quite simple. Use strtok and store each operand in each array ...
But if the user can enter expressions which have n operands then its a bit tricky

tux4life commented: Good :) +8
abhimanipal 91 Master Poster

simply use the format change function in the printf like so, and you will print your numbers as binary

printf("%b", &dec)

This is wrong.

int main()
{   
    int num= 10;
    printf("%d %b %b\n",num,&num,num);   // Wrong
                  
    return 0;
}

The output for this is 10 b b
You can print a number is hexadecimal or octal by using %x and %o respectively but this logic cannot be extended for printing in binary format. In fact I do not believe %b is a legal format specifier for printf

jonsca commented: "anonymous" is just some stupid stupid stupid spammer anyway +4
abhimanipal 91 Master Poster

I dont think you code is logically correct. If I give the input as 4, the successive values of rem will be 0,0,1. But the final value in ans will just 1. So in the 2 while loop you will just get 1 as the answer.

The usual method used to convert a decimal to binary number is to store the successive numbers in a stack and then pop the stack. You can avoid the stack if you can think up of bit wise operations to store and retrieve the remainders in a 4 byte integer

abhimanipal 91 Master Poster

Your syntax is correct. But your procedure is HORRIBLY wrong. In one of my earlier posts I told you to google for some specific functions. Have you done that ?

tux4life commented: Yes. +8
abhimanipal 91 Master Poster

Replace getch() with cin.get()

abhimanipal 91 Master Poster

@choragos ...
Check out the strtok function.... I think that might solve your problem....

abhimanipal 91 Master Poster

@thelamb, dylan9

the reason why the program blows up when you use char codes is that in the addNode function, he is comparing string by using relational operator. This is possible only only in the string class, but if we substitute the string by char array the comparison part will get shot to hell

@thelamb
dylan has posted a lot of code. For the part he/she was stuck he/she is not asking the code but just the general idea. I dont this this is the case of a typical leech who comes here with the sole purpose of getting his work done by others

abhimanipal 91 Master Poster

I have file(.txt) that the program reads on and it outputs the words aphabetically and if the word has been seen, it adds a count to it

This is being done with which data structure ?
If you want to use the binary tree for counting the frequency of the words, you can use inorder to check if the word exists in the tree. If it does, increment the count by 1. If it does not, create a new node

abhimanipal 91 Master Poster

Your first post says that you have to use functions ... Do you know what functions are ? Post #5 contains the skeleton of a function in C++.
This link gives you another example
http://www.cplusplus.com/doc/tutorial/functions/

Now you want to move the part of code between line 22-24 in the function call. Also make the array a global variable. This will make your life easy when you are using functions

abhimanipal 91 Master Poster

B tress are pretty common. You might want to check out suffix trees as well.

abhimanipal 91 Master Poster

There are 2 -3 compile time errors in your code..

#include<iostream>
#include<vector>
#include<iomanip>
#include<string>
using namespace std;
class Person
{
private:
string name;

// Make this bestFriendName. You have used bestFriendName in the function definitions 

Person* bestFriend;
int count;
public:
void setName(string n)
{
name = n;
}
string getName()
{
return name;
}
void setBestFriend(Person *p)
{
// This should be p not b
bestFriendName = b;
}
Person* getBestFriend()
{
return bestFriendName;
}
void setCount()
{
count = count + 1;
}
void display()
{
cout << "name: " << name << endl;
cout << "bestfriend: " << (*getBestFriend()).getName() << endl;
cout << "popularity: " << count << endl;
}
};
int main()
{
string yourName = "";
string bestFriendName = "";
int number = 0;
bool done = false;

vector<Person>persons;
Person myPerson[20];
cout << "Enter name (-1 to stop): "<< endl;
getline(cin, yourName);
while(yourName != "-1")
{
// No need for this line. Memory is already allotted when you create the array of objects
myPerson[number] =new Person;
myPerson[number++].setName(yourName);
cout << "Enter name (-1 to stop): " << endl;
getline(cin, yourName);


if (yourName == "-1")
{
for(int i = 0; i < number; i++)
{
cout << "Enter my best friend of" << myPerson[i].getName() << endl; 
getline(cin,bestFriendName);
} 
}
}

for(int i = 0; i < number; i++)
{
myPerson[i].display();
}
system("pause");
return 0;
}

This should clear your compile time bugs... But there are logical bugs in your code. When I ran your code I …

e30rapidic commented: big help +0
abhimanipal 91 Master Poster

All the choice should be inside the for loop. From the code that you have posted, your for loop ends after the first if statement.

abhimanipal 91 Master Poster

Also for your program it would make sense to change the data type of choice to int as opposed to what you have now

abhimanipal 91 Master Poster
struct Foo
{
    char* value;
};

 // are a and b created in the data segment of the asm. The data is probably is the code segment
struct Foo a = {"Hello from variable a"}; 
struct Foo b = {"Hello from variable b"};

int main()
{
    // what will happen here:
    struct Foo* ptr = &a;
    free(ptr);   // This is will give you an error. The reasons are explained above

    // In the malloc call you allot some memory. The address of this memory is stored in bar
    struct Foo* bar = (struct Foo*)malloc(sizeof(struct Foo));

// Now you store the address of the variable b in the variable bar. The address of the previous memory is lost
    bar = &b;
    
// what happened to the the original contents of bar->value?They got lost
    bar->value = (char*)malloc(sizeof(char)*2);  
    bar->value[0] = 'H';
    bar->value[1] = 'i';

    free(bar->value);
    free(bar); 
 // This is an error because you are trying to free the memory in which the global variable b is stored. As explained above free should only be called when memory is obtained dynamically. You got memory dynamically but lost the address of that memory. So free will give you an error

    return 0;
}
abhimanipal 91 Master Poster

The method used by you to check if the num exists in that particular row or column is correct (though inefficient )

Checking if the number exists in that box is a bit tricky ..... You want some thing of this sort

// All the boxes are 3 * 3 in size
When you input the row number there are 3 possibilities .

Possibility 1: Row_num is 1, 4,7 
You identify these cases because row_num % 3 produces the same result ie 1. If the row_num is in this case you have to consider the rows,
row_num, row_num +1, row_num +2
 
Possibility 2: Row_num is 2, 5,8 
You identify these cases because row_num % 3 produces the same result ie 2. If the row_num is in this case you have to consider the rows,
row_num-1, row_num , row_num+1

Possibility 3: Row_num is 3, 6,9 
You identify these cases because row_num % 3 produces the same result ie 0. If the row_num is in this case you have to consider the rows,
row_num-2, row_num-1 , row_num 

You do the same thing for col_num

Once you get the beginning and the ending of the rows and columns... Then it is easy

for(row_begin........ row_end)
{
     for(col_begin ........ col_end)
      {
             // Do the checking here

       }
}
jephthah commented: yeah, i like this guy. +7
rlhh commented: Great guy, been a great help and has great patience. :) +1
abhimanipal 91 Master Poster

The logic that I would use for this problem will be as follows :

Input Array A[50]:
Temp Array B[50]

for(i=0;i<50;i++)
B= A - target

Sweep thru B and find the greatest -ve number and the smallest positive number . Let the indexes of these values be i1 and i2
A[i1] is the greatest number less than the target. A[i2] is the smallest number greater than the target

Adak commented: Sweet! +2 +2
abhimanipal 91 Master Poster

Right ......
I have given you the logic .....Make the correction on your own

abhimanipal 91 Master Poster

This is a basic algo for checking if a number is prime or not

Store the number in a

Loop: From i= 2 till i= sqrt(a)+1
          if(a%i==0)
              break
          else 
               Do nothing

if(i==sqrt(a)+1)
     This means that no number between 2 and sqrt(a) is a factor for a.   which means a is a prime number
else
      a is not a prime number

Now You can extend the above logic to solve your problem

abhimanipal 91 Master Poster

Are you printing on the server like this ?

printf("Calender server has TCP Port %d and IP address %d ", SERVERPORT); // server IP is missing

Then the problem is that printf has just one argument but 2 "%d", so the first %d will print SERVERPORT and the other one will print garbage

You will notice that in the server you have written a while(1). This means that the server can serve an infinite number of requests. If you want to just server any 2 requests then change the while(1) to for(i=0;i<2;i++)

abhimanipal 91 Master Poster
abhimanipal 91 Master Poster

One way could be to put a if condition before the mod operation. If c is equal to a, dont do the mod operation. Else go ahead and do the mod operation

Xufyan commented: thanks...xufyan +1
abhimanipal 91 Master Poster

I want my code to take two characters and print them, but this code only takes one character, prints it and terminates, can you please tell me what's wrong with it? Thank you.

#include <stdio.h>
 int main()
 {
         char a, b;
         scanf("%c", &a);
         scanf("%c", &b);

         printf("%c %c\n", a,b);

         return 0;
 }

When you enter the first character you are actually entering 2 characters. The character itself and ('\n') when you hit the enter key. So both the scanf's get satisfied. The solution is to use fgets as suggested above

abhimanipal 91 Master Poster

If you are having trouble getting started, think on the lines of linked lists. Store each number in 1 node of a linked list. So now the size of the number is not a criterion any more.
So for adding just scan both the lists and store the result in the third list. Take care of the carry though

Ancient Dragon commented: Linked list -- good suggestion :) +26
abhimanipal 91 Master Poster

fork system call returns the process id of the child and parent. You could use this information

abhimanipal 91 Master Poster

I am not sure if this will help, but could you over write the data you want to be removed, with spaces ?

Ancient Dragon commented: my thoughts too +26
abhimanipal 91 Master Poster

You could use the division operator to convert marks from 1-100 range to 1-10. Then you just have to write 10 switch cases

abhimanipal 91 Master Poster

The objective of BFS is to print all the nodes at a given level, then move to the next level

In DFS we go depth wise as far as we can go. Then when we cant go any further we backtrack and then try again and so on.

DFS gives you a forest because you have many connected components as opposed to BFS where you have only 1 connected component. (Read the definition of connectivity for better understanding of this)

abhimanipal 91 Master Poster
abhimanipal 91 Master Poster

Use fread to read from the file . Check out this link
http://irc.essex.ac.uk/www.iota-six.co.uk/c/i2_feof_fgets_fread.asp

while(check till end of file)
{
  /* 
        fread will put the data in array1
         After that use string copy to move the data to character pointer  array...lets say array2
*/
}
abhimanipal 91 Master Poster

There are many mistakes in your code

1. When you wanted to remove the number 6, you took the ASCII value of 6 ie 54 but forgot to subtract the ASCII value of 0. Hence your i variable became too big.
2. When you read the number 6 you have only 5 characters to read. So the for loop should not be <= but just <
3. When you start the second iteration, the value of c is 4 but the value of m is already greater than 4 so it does not enter the loop
4. Ensure that after you have finished reading the frame , the value of has decremented upto the correct value
5. After you have made all these changes , remove scanf and use fgets instead

abhimanipal 91 Master Poster

Hello People... I found this sample code online

int main(int argc, char* argv[])
{
        struct bitfield
        {
                signed int a:3;
                unsigned int b:13;
                unsigned int c:1;
        };
        struct bitfield bit1={2,14,1};
        printf("%d",sizeof(bit1));


        return 1;
}

I compiled this code on linux with gcc compiler and the output I got for this is 4. Can any one explain why this so ?

abhimanipal 91 Master Poster

I want to see your print function . If it is some thing of this sort

for(i=0;i<20;i++)
                printf("%d\n",arr3[i]);

Then you will get junk characters in the ending. The reason for this is that there are less than 20 numbers in arr 3.