1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
/*
Name: fgets vs scanf
Copyright: GPL
Authors: Samy Hocine and some members of the C forum from developpez.com
Date: 03/09/07 09:24
Description: Little code
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "myHeader.h"
int main(void)
{
//Example with good functions
char str[256], str2[256];
puts("Example with good functions");
puts("str =");
fgets(str, sizeof str, stdin);
fclean(str, stdout);
puts("str2=");
fgets(str2, sizeof str2, stdin);
fclean(str2, stdout);
if(strcmp (str, str2) == 0)
puts("str = str2");
else
puts("str != str2");
getch();
system(CLEAR);
//Example with a difficult functions reserved for good programmers
puts("Example with bad functions");
printf("str=");
scanf("%s", str);
printf("str2=");
scanf("%s", str2);
if(strcmp (str, str2) == 0)
puts("str = str2");
else
puts("str != str2");
getch();
return 0;
}
//So if you're a beginner, you should use fgets ! |
Partager