What i've written below is a much simplified version of my program but it has the exact same problem (didn't want to bore people with long code).
I wrote the printf's appropriate to what the code does or doesn't do.
it doesn't take the fgets (in the function) in the second while loop but never the first, and i want it to take a string in the first.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int this_is_functio n()
{
char anotherBuffer[255];
char test2[] = "win";
printf("This fgets doesn't catch first time.\n>> ");
fgets(anotherBu ffer, 4, stdin);
printf("%s\n", anotherBuffer);
if (strcmp(test2,a notherBuffer) == 0){
printf("success ");
return 1;
}
return 0;
}
int main(void)
{
char *buffer;
char test1[] = "hello";
buffer = (char*)malloc(2 55);
printf("If i enter some input here.\n>> ");
fgets(buffer, 6, stdin);
printf("%s\n", buffer);
if (strcmp(buffer, test1) == 0){
while (this_is_functi on() == 0)
printf("Error") ;
}
free(buffer);
}
any ideas? thanks in advance
I wrote the printf's appropriate to what the code does or doesn't do.
it doesn't take the fgets (in the function) in the second while loop but never the first, and i want it to take a string in the first.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int this_is_functio n()
{
char anotherBuffer[255];
char test2[] = "win";
printf("This fgets doesn't catch first time.\n>> ");
fgets(anotherBu ffer, 4, stdin);
printf("%s\n", anotherBuffer);
if (strcmp(test2,a notherBuffer) == 0){
printf("success ");
return 1;
}
return 0;
}
int main(void)
{
char *buffer;
char test1[] = "hello";
buffer = (char*)malloc(2 55);
printf("If i enter some input here.\n>> ");
fgets(buffer, 6, stdin);
printf("%s\n", buffer);
if (strcmp(buffer, test1) == 0){
while (this_is_functi on() == 0)
printf("Error") ;
}
free(buffer);
}
any ideas? thanks in advance
Comment