C String input confusion

Posted by ahref on Stack Overflow See other posts from Stack Overflow or by ahref
Published on 2010-04-06T20:12:28Z Indexed on 2010/04/06 20:13 UTC
Read the original article Hit count: 189

Filed under:
|
|

C really isn't my strong point and after reading 3 chapters of a book on the subject and spending ages trying to get stuff working it just doesn't:

#include <stdio.h>
char *a,*b;
int main( )
{
     char input[10];
     fgets(input,sizeof input, stdin);
     a = input;
     fgets(input,sizeof input, stdin);
     b = input;
     printf("%s : %s",a,b);

}

I've isolated the problem from my main project. This code is meant to read in two strings and then print them however it seems to be setting a and b to point to input. Sample output from this code when A and B are entered is(don't worry about the \n's i can remove them):

A
B
B
 : B

How do i store the value of input in another variable eg. a or b so that in the above case

A
B
A
 : B

Is output?

Thanks

© Stack Overflow or respective owner

Related posts about c

    Related posts about string