Created
June 10, 2015 13:30
-
-
Save gnitnaw/ac3dbcd8fa8e11c515c8 to your computer and use it in GitHub Desktop.
fflush use?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAXSIZE 256 | |
void read_string(char* p); | |
int main(void) { | |
char c, s[MAXSIZE]; | |
puts("I/O lib"); | |
puts(""); | |
printf("Please give me a char: "); | |
c = getchar(); | |
printf("What you keyin is %c\n", c); | |
// fflush(stdin); | |
while(getchar()!='\n'); | |
printf("Please give me a string : "); | |
read_string(s); | |
printf("What you keyin is %s\n", s); | |
printf("\n Press <Enter> to continue..."); | |
while ((c=getchar()) != '\n'); | |
return 0; | |
} | |
void read_string(char* p) { | |
int i; | |
char c; | |
for (i=0; i<MAXSIZE-1; ++i) { | |
if ( (c=getchar()) != '\n' ) { | |
p[i] = c; | |
} else { | |
break; | |
} | |
} | |
p[i] = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment