C program that takes input "FName|LName" and outputs to std out
FAST HELP NEEDED!!!!!!
I am new to the C language....... This is my problem:
I need to write a C program to read in a persons name. The name will be passed to me in this format
FName | LName
If I was able to prompt for first name and last name that would no problem but in this situation I can't. I need to read in the single string and and store the fname and lname.
This is what I currently have which is not working because I have incompatible types and comparison between pointer and integer errors, I'm sure there is a better way to do this instead of these if statements. I was thinking of sscanf but i'm not 100% sure how to use this, like I said I am new to C.
Here is my code its a very simple program (it should be):
main()
{
char buff[50];
char fname[25];
char lname[25];
int pipe = 0;
int k = 0;
memset(fname, '\0', sizeof(fname));
memset(lname, '\0', sizeof(lname));
while (gets(buff) != EOF)
{
gets(buff);
fname = ' ';
lname = ' ';
while (k <= length(buff))
{
if (buff[k] =='|')
pipe = 1;
if ((pipe = 0) && (buff[k] != '|'))
fname = fname + buff[k];
if ((pipe = 1) && (buff[k] != '|'))
lname = lname + buff[k];
k++;
}
}
printf("%s%s%s" , fname, lname, fname"."lname"@xxxxxxx.com");
}
PLEASE HELP
FAST HELP NEEDED!!!!!!
I am new to the C language....... This is my problem:
I need to write a C program to read in a persons name. The name will be passed to me in this formatt
FName | LName
If I was able to promt for first name and last name that would no problem but in this situation I can't. I need to read in the single string and and store the fname and lname.
This is what I currently have which is not working because I have incompatible types and comparison between pointer and integer errors, I'm sure there is a better way to do this instead of these if statements. I was thinking of sscanf but i'm not 100% sure how to use this, like I said I am new to C.
Here is my code its a very simple program (it sould be):
main()
{
char buff[50];
char fname[25];
char lname[25];
int pipe = 0;
int k = 0;
memset(fname, '\0', sizeof(fname));
memset(lname, '\0', sizeof(lname));
while (gets(buff) != EOF)
{
gets(buff);
fname = ' ';
lname = ' ';
while (k <= length(buff))
{
if (buff[k] =='|')
pipe = 1;
if ((pipe = 0) && (buff[k] != '|'))
fname = fname + buff[k];
if ((pipe = 1) && (buff[k] != '|'))
lname = lname + buff[k];
k++;
}
}
printf("%s%s%s" , fname, lname, fname"."lname"@xxxxxxx.com");
}
PLEASE HELP
|