source: trunk/Softwares/Basic_test.or32/src/c/func_test_io.c @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 1.7 KB
Line 
1#include "func_test_io.h"
2#include <errno.h>
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6
7//-----[ func_test_io ]---------------------------------------------------------
8
9bool func_test_io()
10{
11  /*
12  {
13    FILE       * file;
14    const char * filename = "files/write.txt";
15    const char * string   = "La technologie au service de la paix\n";
16
17    printf("Test write in file\n");
18   
19    if ((file = fopen (filename,"w")) == NULL)
20      printf("fopen  : Ko - errno : %x - %s\n",errno,strerror(errno));
21    else
22      {
23        printf("fopen  : Ok\n");
24   
25        if (fputs (string,file) == EOF)
26          printf("fputs  : Ko - errno : %x - %s\n",errno,strerror(errno));
27        else
28          printf("fputs  : Ok\n");
29
30        if (fputs ("La paix par le pouvoir\n",file) == EOF)
31          printf("fputs  : Ko - errno : %x - %s\n",errno,strerror(errno));
32        else
33          printf("fputs  : Ok\n");
34   
35        if (fclose (file) == EOF)
36          printf("fclose : Ko - errno : %x - %s\n",errno,strerror(errno));
37        else
38          printf("fclose : Ok\n");
39      }
40  }
41  */
42  {
43    FILE       * file;
44    const char * filename = "files/read.txt";
45    char * string = (char *) malloc (100);
46
47    printf("Test read  in file\n");
48   
49    if ((file = fopen (filename,"r")) == NULL)
50      printf("fopen  : Ko - errno : %x - %s\n",errno,strerror(errno));
51    else
52      {
53        printf("fopen  : Ok\n");
54        string = fgets (string,50,file);
55       
56        while (string != NULL)
57          {
58            print (string);
59            printf("fputs  : %s\n",string);
60            string = fgets (string,50,file);
61          }
62           
63        print(string);
64       
65        if (fclose (file) == EOF)
66          printf("fclose : Ko - errno : %x - %s\n",errno,strerror(errno));
67        else
68          printf("fclose : Ok\n");
69      }
70  }
71  return true;
72}// end fct func_test_io
Note: See TracBrowser for help on using the repository browser.