0
I run my program and it’s all right until I get to
"l[strlen(l) - 1] = l[strlen(l)]; while (fgets(ll, sizeof (ll), "EventosDesportivosFutebol.txt") != NULL)"
, (doing the debug I was able to find out where I crashed), but I am not able to solve the problem, below is the code:
while (camp<5) {
printf("Altere Jogos da Liga dos Campeões %d: ", camp+1);
scanf("%s", Jogos[camp].campeoes);
while (getchar() != '\n');
camp++;
char l[20] = "Liga dos Campeões";
char ll[20] = {l};
fgets(l, sizeof(l), stdin);
l[strlen(l) - 1] = l[strlen(l)];
while (fgets(ll, sizeof (ll), "EventosDesportivosFutebol.txt") != NULL)
if (strstr(ll, l) != NULL)
{
memset(l, NULL, 1000);
}
fclose("EventosDesportivosFutebol.txt");
feventosDesportivosFutebol = fopen("EventosDesportivosFutebol.txt", "w");
if (feventosDesportivosFutebol != NULL) {
fprintf(feventosDesportivosFutebol, "\n\nLiga dos Campeões:\n\n");
for (camp = 0; camp<5; camp++) {
fprintf(feventosDesportivosFutebol, "%s\n", Jogos[camp].campeoes);
}
}
fclose(feventosDesportivosFutebol);
Someone could help me?
So this is my code:
while (camp<5) {
printf("Altere Jogos da Liga dos Campeões %d: ", camp+1);
scanf("%s", futebol[camp].campeoes);
while (getchar() != '\n');
camp++;
}
feventosDesportivosFutebol = fopen("EventosDesportivosFutebol.txt", "w");
if (feventosDesportivosFutebol != NULL) {
fprintf(feventosDesportivosFutebol, "\n\nLiga dos Campeões:\n\n");
for (camp = 0; camp<5; camp++) {
fprintf(feventosDesportivosFutebol, "%s\n", futebol[camp].campeoes);
}
}
fclose(feventosDesportivosFutebol);
Here the code works well, but when you scroll to the file (e.g. Sporting - Benfica), only Sporting is recorded. And I searched the net for some help and I found that comparing strings but I am not able to frame and so give error, will help me?
Joseph could give a brief explanation of the code?
– gato
I’m sorry I was missing the rest of the code, I could review what’s wrong in all the code pf josé?
– ricascross
@ricascross: your code still has an error in "fgets" and the first "fclose", see the example I wrote..., but complete, which can be compiled and tested to facilitate understanding (yours and the readers of the OS)
– zentrunix
I’ll edit and doubt!
– ricascross