Προς το περιεχόμενο

Βοήθεια με κώδικα C# - πρόβλημα στην fscanf


Pigimon

Προτεινόμενες αναρτήσεις

Δημοσ.

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include <string.h>

 

 

 

 

 

typedef struct komvos{

int value;

komvos *next;

}komvos;

 

 

 

typedef struct Student{

int AM;

char name[10];

char surname[10];

int year;

Student *next;

}Student;

 

typedef struct Tel{

int AM;

int tel[10];

Tel *next;

}Tel;

 

 

typedef struct Studlist{

Student *head;

}Studlist;

 

typedef struct Phonelist{

Tel *head;

}Phonelist;

 

 

 

int StudentLoader(int popul){

Student *L;

L=(Student *) malloc (sizeof(Student));

FILE *stud;

srand(time(0));

int i=0,j=0;

if ((stud=fopen("MyStudentz.txt","w")) == NULL) {

printf("Den itan dinato na anoiksei to arxeio");

return 0;

}

else{

stud=fopen("MyStudentz.txt","w");

for (i=1;i<popul+1;i++){

L->AM=i;

L->year=(rand()%17)+1990;

for (j=0;j<10;j++){

L->name[j]= (65+rand()%26);

L->surname[j]= (65+rand()%26);

}

fprintf(stud,"%d\t",L->AM);

for (j=0;j<10;j++){

fprintf(stud,"%c",L->name[j]);

}

fprintf(stud,"\t");

for (j=0;j<10;j++){

fprintf(stud,"%c",L->surname[j]);

}

fprintf(stud,"\t");

fprintf(stud,"%d\n",L->year);

}

fclose(stud);

}

}

 

 

int insertathead(Studlist *L,int AM,char nam[10],char surnam[10],int yer){

Student *node;

int i=0;

node=(Student *) malloc (sizeof(Student));

if (node == NULL){

printf("Insuficient Memory!");

return 0;

}

else {

node->AM=AM;

for(i=0;i<10;i++){

node->name=nam;

node->surname=surnam;

}

node->year=yer;

node->next=L->head;

L->head=node;

}

}

 

 

void FileReader(Studlist *L){

FILE *stud;

int am=0,year=0,i=0,j=0;

char name[10],surname[10];

if ((stud=fopen("MyStudentz.txt","r")) == NULL){

printf("To arxeio den yparxei!");

}

else{

for(j=0;j<1000;j++){

fscanf(stud,"%d %s %s %d",&am,&name,&surname,&year);

insertathead(L,am,name,surname,year);

//printf("%d %s %s %d\n",am,name,surname,year);

}

}

fclose(stud);

}

 

void insertatphead(Phonelist *P,int am,int tele[10]){

Tel *node;

int i=0;

node=(Tel *) malloc (sizeof(Tel));

if (node == NULL) { printf("Insuficient Memory!");}

else{

node->AM=am;

for(i=0;i<10;i++){

node->tel=tele;

}

}

}

 

int Teloader(int popul){

Tel *T;

int i,j=0,k=0;

srand(time(0));

T=(Tel *) malloc (sizeof(Tel));

FILE *Til;

if ((Til=fopen("MyTel.txt","w")) == NULL ){

printf("Ta tilefona den iparxoun filos");

return 0;

}

else{

for (i=1;i<popul+1;i++){

for(j=0;j<3;j++){

T->AM=i;

fprintf(Til,"%d\t",T->AM);

for(k=0;k<10;k++){

T->tel[k]=rand()%10;

fprintf(Til,"%d",T->tel[k]);

}

fprintf(Til,"\n");

 

}

}

}

fclose(Til);

}

 

void PhileReader(Phonelist *P){

FILE *Til;

int am,j=0,p=0,k=0;

int tel;

if ((Til=fopen("MyTel.txt","r")) == NULL){

printf("To arxeio den yparxei!");

}

else{

for(j=0;j<3000;j++){

fscanf(Til,"%d %d",&am,&tel);

printf("%d\n",tel);

}

fclose(Til);

}

}

 

 

 

 

void ListDisplay(Studlist L){

Student *cur;

cur=(Student *) malloc (sizeof(Student));

cur=L.head;

while (cur != NULL){

printf("AM:%d ",cur->AM);

printf(" ONOMA: ");

for (int i=0;i<10;i++){

printf("%c",cur->name);

}

printf(" EPONIMO:");

for (i=0;i<10;i++){

printf("%c",cur->surname);

}

printf(" YEAR:%d",cur->year);

printf("\n");

 

cur=cur->next;

}

}

 

 

 

main(){

FILE *stud,*Til;

Phonelist P;

Studlist L;

Student S;

int yea=0,n=0,s=0,p=0,i=0;

char nam[10],surnam[10];

L.head=NULL;

StudentLoader(1000);

Teloader(1000);

FileReader(&L);

PhileReader(&P);

//ListDisplay(L);

 

return 0;

}

 

 

ΣΤΗΝ ΣΥΝΑΡΤΗΣΗ PHILEREADER Η FSCANF ΔΕΝ ΔΙΑΒΑΖΕΙ ΣΩΣΤΑ ΤΑ ΤΗΛΕΦΩΝΑ ΕΝΩ ΤΑ ΑΜ ΣΩΣΤΑ ΑΝ ΕΧΕΤΕ COMPILER ΤΡΕΞΤΕ ΤΟ!

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...