#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "string.h"
#include "ctype.h"

typedef struct
{
    char name[30];
    int apousies;


}telikaT;    


void ypologismoi(FILE *inArxeio,telikaT students,int *p100,int *pAll);
void emfaniseis(FILE *outArxeio,telikaT students,int *p100,int *pAll);


main()
{
    FILE *inArxeio,*outArxeio;
    telikaT students[30];
    int p100,pAll;



ypologismoi(inArxeio,students,&p100,&pAll);    
emfaniseis(outArxeio,students,&p100,&pAll);    








system("pause");    
}    
void ypologismoi(FILE *inArxeio,telikaT students,int *p100,int *pAll)
{
    char infilename[30];
    char name[30];
    int apousies;
    char sxolia[68],termch;
    int sarwseis;
    *pAll=0;
    *p100=0;
    while(TRUE)
    {
    printf("Enter the name of the file : ");
    gets(infilename);
    inArxeio=fopen(infilename,"r");
    if(inArxeio!=NULL)
    {
    break;
    }
    printf("Cannot open file %s  ///\\\ Try again!\n",infilename);

    }

    while(TRUE)
    {
        sarwseis=fscanf(inArxeio,"%30[^,], %d, %68[^\n]%c",name,&apousies,sxolia,&termch); 

        if(sarwseis==EOF)
          break;
        if(sarwseis!=4 || termch!='\n')
         printf("Error\n");

         if(apousies>100)
         {
                strcpy(students[*p100].name,name);
                students[*p100].apousies=apousies;
                (*p100)++;

         }

         (*pAll)++;

    }

    fclose(inArxeio);
}

void emfaniseis(FILE *outArxeio,telikaT students,int *p100,int *pAll)
{
    int i;
    char outfilename[30];


    printf("Type the name of the NEW file : ");
    gets(outfilename);
    outArxeio=fopen(outfilename,"w");
    fprintf(outArxeio,"%-30s %9s","ONOMATEPWNYMO","APOYSIES");
    for(i=0;i<40;i++)
    fprintf(outArxeio,"%c","-");
    fprintf("\n");

    for(i=0;i<*p100;i++)
    fprintf(outArxeio,"%-30s %9d\n",students[i].name,students[i].apousies);

    for(i=0;i<40;i++)
    fprintf(outArxeio,"%c","-");

    fprintf("\n");

    fprintf("SYNOLO MATHITWN: %d\n",*pAll);
    fprintf("SYNOLO APONTWN: %d\n",*p100);

}        

**I cannot figure out how can i pass a struct threw a void function.
Also can you tell me what can i do for the program to work fine??
Thanks in advance.....sorry for my terrible english **

You need to pass a pointer to the struct declared in main(), not the struct itself. Since you declared students as an array of structs you have to tell ypologismoi() which one it needs. For example:

ypologismoi(inArxeio,&students[0],&p100,&pAll);

If your intent is to pass the entire array, then change the function signature

void ypologismoi(FILE *inArxeio,telikaT students[],int *p100,int *pAll)

i want to pass the entire new array. Thans for helping...i will tell you if it works :-)

Now iam facing with two errors:

#
**
1)
It says that in function "ypologismoi"

58:12 C:\Programs\Dev-Cpp\a2f9.c [Warning] '\040' [enabled by default]

2)
It says that in function "emfaniseis"

**109:5 C:\Programs\Dev-Cpp\a2f9.c [Warning] passing argument 1 of 'fprintf' from incompatible pointer type [enabled by default]

expected 'struct FILE *' but argument is of type 'char *'**

What should i do for these errors ?

  1. remove ///\\ and see if that removes the warning

  2. lines 106, 108 and 109: fprintf() is missing the first parameter FILE*, see line 97 for correct syntax.

ΟΟΟΟ!!!!!!!!! THANK YOU VERY VERY MUCH!!!!!!!!!!!

I own you my life !!!!!

Also thanks for your immediatedly answer....

You rock!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.