Hello, I am having a little bit of a problem. I posted a question a little while ago about passing strings back from functions, and found this forum very hospitable to a newbie, so i'm back with another question.
My function to request the user's information is:
void edt_usr_init(char *finit, char *minit, char *linit)
{
/* Clear the screen */
system ("cls");
/* Prompt for and recieve user initials */
printf ("Enter User's initials (xxx) >>\n");
scanf (" %c%c%c", finit, minit, linit);
}
My function to write to a file, for practice purposes, is:
(I'm using this to check the values that will eventually all be contained is strings, but these results weren't expected. A call to printf first made me aware of it.)
void usr_info(void)
{
char ini[3];
int kg;
FILE *outp; /* pointer to output file */
outp = fopen("practice/usr_stat.txt", "a"); /* open the output file to append it */
edt_usr_init(&ini[0], &ini[1], &ini[2]); /* get the user's info */
edt_usr_wght(&kg); /* get the user's weight */
fprintf(outp, "\n%s\n%d", ini, kg); /* print output to file */
fclose(outp); /* close the output file */
}
for an input of "jab" for usr_init fuction and "104" for usr_wght, my text file ends up reading...
jab€ÿ
104
I don't quite get it. If I make the string longer assuming that "\0" will be placed at the end of data input, which is what i thought i was doing by making the string length [3], it just changes the funny characters after my user input.
If anyone has any thoughts, I'd be grateful. Thank you.