Hi everyone
I was fiddling with some code ln and came across a dilemma ,here is the code
ok so whats the problem, well if i run this program as is the gets function is never called or (skipped) so i never get to input some text.Code:# include <stdio.h> # include <conio.c> /********************************** FUNCTION PROTOTYPES ********************/ int test(void); /********************************** BEGIN MAIN ****************************/ int main(int argv, char *argc[]) { int number; printf("Enter a number:"); scanf("%d",&number); switch (number){ case (1): test(); break; } system("PAUSE"); return 0; } /********************************** FUNCTION ******************************/ int test(void) { int f; char name_test[20]; clrscr(); printf("Program is here"); //scanf("%d",&f); gets(name_test); printf(name_test); return 0; }
I found that if i put a scanf function just before the gets function the program halts and allows me to enter input into the char array.
I found tht it was the switch command that was creating all this hassle and i was just wondering why?
Thanx for your help.



LinkBack URL
About LinkBacks


