C programing some errors :(

Posted by Pedro on Stack Overflow See other posts from Stack Overflow or by Pedro
Published on 2010-04-26T20:20:36Z Indexed on 2010/04/26 20:23 UTC
Read the original article Hit count: 188

Filed under:
|

Hi...this is a little code that i'm doing, but i have some errors...:S

Hi have a txt file and i want to "convert to xml", but the program must know what is comments, and must organize...


txt file:

/* Licenciaturas na ESTG-IPVC 2009 – v1.1*/

    - Info, <N Alunos>
<hr>---------------------------------------------------  
3
<hr>---------------------------------------------------  

    - data, <course><Number>;<name>;<email>

    - disciplinas, <n disciplines>;<note>;[<note>;]  
</hr>---------------------------------------------------  
LEI;7671;Name name name;[email protected];  
9;8;12;9;12;11;6;15;7;11;  
LTCGM;6567;nam1 nam2 nam3;[email protected];  
6;13;14;12;11;16;14;  
LEI;7701;xxxxx xxxx xxxx;[email protected];  
8;13;11;7;14;12;11;16;14;  

My code:

int main(int argc, char *argv[])
{

       char first[60];//array
       char comment[60];//array
       char nome_int[60];//array
       char total[60];//array
       char course[60];//array
       int i;
       char notas[60];
       char *number, *name, *mail, *total_disci; 
       int total_cad;
       char disciplines[60];
       printf("Int. the name of the file to convert\n");
       scanf("%s",&nome_int);
       FILE *fp = fopen(nome_int, "r"); //open file
       FILE *conver = fopen("conver.xml","w");// opne output
       FILE *coment = fopen("coment.txt","w");
       if (fp == NULL) { 
       printf("File not found\n");
       exit(1); 
                         }
       else {
             fgets(first, 60,fp);
             fputs(first,coment);
             while (!(feof(fp))){
                                    fgets(first, 60, fp);
                                    if (first[0] == '-'){ 
                                                               fputs(first,coment);
                                                               }


            for(i=1;fscanf(fp,"%s",total)!=-5;i++){ 
                                                     if(i==2){ 
                                                               printf("Total %s",total);//here the program stops
                                                               }
                                                               }



                                    fgets(course,60,fp);
                                    if(course[0]=='L'){
                                                       number = strchr(course, ';');//here course is an array but must be an appointer, what can i do? 
                                                       *number = '\0'; 
                                                       number++;

                                                       name = strchr(number, ';'); 
                                                       *name = '\0'; 
                                                       name++; 

                                                       mail= strchr(name, ';'); 
                                                       *mail = '\0'; 
                                                       mail++;
                                                       char *curso1;
                                                       total_cad=atoi(total_disci); 
                                                       printf("Course: %s\n",course);
                                                       printf("Number: %s\n",number);
                                                       printf("Name: %s\n",name);
                                                       printf("e-mail: %s\n",mail);
                                                       }
                                                       fgets(disciplines,60,fp);//here crash
                                                       total_disci= strchr(mail, ';'); 
                                                       *total_disci = '\n'; 
                                                       total_disci++; 
                                                       printf("Total disciplines: %d\n",total_cad);


                               }
                               }            


    fclose(fp);
    fclose(coment);
    fclose(conver); 



  system("PAUSE");  
  return 0;
 }

the convert file must be like this:

<xml>
    <list_courses>
        <course>
            <sigla>LEI</sigla>
                <NAlunos>2</NAlunos>
                    <list_students>
                         <students>
                             <number>7671</number>
                             <name>name name name</name>
                             <email>[email protected]</email>
                             <stat>disaproved</stat>
                             <media_notes>10</media_notes>
                             <biggest_note>15</biggest_note>
                             <small_nota>6</small_nota>
                         </students>
                     </list_students>
                 </course>
         </list_courses>
</xml>

_______________________________________-

now separated by only comment on what is what and converted to xml. also had to do was impressed that the program could name, email address, number, etc. .. here the main errors

do not want to do for me, just want to see the errors, I spent the whole day right back from them and nothing ...

someone who can help, please do it :)

© Stack Overflow or respective owner

Related posts about c

    Related posts about homework