I've been getting some errors in my program and even the debugger helped.
Here's the .h
#ifndef PROJETOIAPG_PROJETO_H
#define PROJETOIAPG_PROJETO_H
#define TAM_S 30
typedef struct client {
char name[15], surname[15];
int id;
} CLIENT;
int main();
int read_client(CLIENT client[]);
#endif
And here is the file .c
#include <stdlib.h>
#include <projeto.h>
#include <stdio.h>
int main(){
CLIENT client;
read_client(&client);
return 0;
}
int read_client(CLIENT client[]) {
int i=0,num_c=0;
FILE fp;
fp = fopen("Client.txt","r");
if( fp == NULL ) {
printf("\nError!\n");
}
else
{
fscanf(fp , "%d\n" , &num_c);
for(i=0;i<num_c;i++)
{
fscanf(fp , "%d " , &client[i].id);
fscanf(fp , "%s " , &client[i].name);
fscanf(fp , "%s\n" , &client[i].surname);
printf("\nid:%d " , client[i].id);
printf("\nname:%s " , client[i].name);
printf("\nsurname:%s" , client[i].surname);
}
}
fclose(fp);
return 0;
}
The file is like this
5
1 Manuel Monteiro
2 Maria Fernandes
3 Ines Cornio
4 Fernanda Guimaraes
5 Fernanda Guimaraes
The problem is that I always get different erros about it. If I change the size of the char nome[number] for a bigger number it works for half or doesen't even work at all but even like how it is it gives the error Process finished with exit code -1073740791 (0xC0000409)
User contributions licensed under CC BY-SA 3.0