Wolmer’s Trust High School for Girls

INFORMATION TECHNOLOGY (GENERAL PROFICIENCY)

 

Grade: 11                                                        Teacher:  Mrs. McCallum-Rodney

 

PSEUDOCODE EQUIVALENT FOR FILES

 

Example 1 in C

 

if((dataptr = fopen(“DataFile.txt”, “w”)) == NULL)

{

for(int pos = 0; pos < 5; pos++)

{

            fprintf(dataptr, “%s\n%s\n”, name[pos], addr[pos]);

}

}

 

Pseudocode equivalent

 

OPEN  DataFile

 

           FOR pos = 0 TO 4

                 WRITE name[pos], addr[pos]

           ENDFOR

 

CLOSE DataFile            

     

 

 

Example 2 in C

 

if((dataptr = fopen(“DataFile.txt”, “r”)) == NULL)

{

for(int pos = 0; pos < 5; pos++)

{

            fprintf(dataptr, “%s\n%s\n”, name[pos], addr[pos]);

}

}

 

Pseudocode equivalent

 

OPEN  DataFile

 

           FOR pos = 0 TO 4

                 READ name[pos], addr[pos]

           ENDFOR

 

CLOSE DataFile            

     

 

Example 3 in C

 

 

if((dataptr = fopen(“DataFile.txt”, “a”)) == NULL)

{

            fprintf(dataptr, “%s\n%s\n”, name, addr);

}

 

 

Pseudocode equivalent

 

OPEN  DataFile

 

           FOR pos = 0 TO 4

                 APPEND name, addr

           ENDFOR

 

CLOSE DataFile            

     

 

 

 

Make a Free Website with Yola.