|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Jun 2003
Messaggi: 893
|
[Linguaggio C]Codice banalissimo che mi fa impazzire!!!!!
Ciao a tutti,
vi posto questo codice davvero banale: Codice:
#include <stdio.h> #include <stdlib.h> main() { FILE *fp, *fpTS, *fpVS, *fpts; char string_name[27]; int ch = 1; fp = fopen("total_test.txt", "r+"); fpTS = fopen("TS.txt", "w+"); fpVS = fopen("VS.txt", "w+"); fpts = fopen("ts.txt", "w+"); if (fp == NULL || fpTS == NULL || fpVS == NULL || fpts == NULL){ printf("\nOpen Error\n"); getch(); exit(1);} // Vi sono 699 patterns - si usino: 233 pattern per il TS, 233 per il VS e 233 per il Test Set //while(!feof(fp)){ while(ch <=699){ fscanf(fp, "%s", string_name); printf("%s\n", string_name); printf("%d\n", ch); if(ch>=1 && ch<=233) fprintf(fpTS, "%s\n", string_name); if(ch>=234 && ch <=466) fprintf(fpVS, "%s\n", string_name); if(ch >= 467 && ch <=699) fprintf(fpts, "%s\n", string_name); ch ++; } fclose(fp); fclose(fpVS); fclose(fpts); printf("\nLetti %d pattern: ", --ch); getch(); } |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Tecnicamente mi sembra corretto. Domanda: quanto sono lunghe le stringhe lette dal file? Devono essere al massimo di 26 caratteri altrimenti avresti un buffer overflow.
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Jun 2003
Messaggi: 893
|
Certo andin,
ma se pensi che la funzione scrive regolarmente nei file TS.txt e VS.txt il contenuto di string_name, per quale arcano motivo non dovrebbe piu scrivere in ts.txt? |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:46.