I'm writing a simple program which takes data about people in this format: name,age,gender,info
and it will display them like this [name: , age: , gender: , info: ]
Here is my code so far:
#include <stdio.h> int main() { char name[10]; int age; char gender[2]; char info[50]; while(scanf("%9[^,],%i,%c,%49[^\n]", name, &age, gender, info) == 4) { printf("[name: %s, age: %i, gender: %c, info: %s]\n", name, age, gender, info); } return 0; }
So I decided to write my output to another text file using >. And it does nto display correctly, the ] bracket displays on a new line and [name: by itself.
This is my input:
eliza,7,F,likes animals bob,9,M,fast at running sue,6,F,likes painting And the output is:
[name: eliza, age: 7, gender: J, info: likes animals ] [name: bob, age: 9, gender: J, info: fast at running ] [name: sue, age: 6, gender: J, info: likes painting ] Can someone help? I can't figure out why it prints the data like this, I tried using strstr() to check if any of my variables contained the new line character.
\r\nnot just\ninfo. To the OP: what compiler are you using, and how do you enter the input?