0

hi
i'm new in program
i want to write code in c .. and i'll convert it to c++
but i've problem

this is the code

#include<stdio.h>
#include<conio.h>


	typedef struct std
{
	int id;
	char name [10];
	char status;
}STD;

void main()

{
	STD m;
	printf("Enter  id : ");
	scanf("%d",&m.id);
	printf("\n Enter name : ");
	scanf("%c",&m.name);
	printf("\n Enter status : ");
	scanf("%c",&m.status);
	printf("The Day Is : %d / %c / %c ",m.id,m.name,m.status);
	getch();
}

Now ,

when i run code , it is run ...
i put id .. ok
the next step is to put name , the program terminated it and ask for status dirct ..
after i put status ..
the info displayed ... but the name deos not appear ..
i guss the problem with " Char Array "
i'm not good with it..
please help me..

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by UmH
0

- This is not a C++ question, but a C question.
- Why not to use scanf

If you want to use scanf to get a char array from input, you should use %s instead of %c. Same goes for printf.
So change: scanf("%c",&m.name); to: scanf("%s",&m.name); Make the same change for your printf.

Edited by Nick Evan: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.