Move the sources to trunk
[opencv] / apps / Hawk / CVEiCL / EiC / module / stdClib / test / testfopen.c
1 #include "stdio.h"
2 #include "string.h"
3 #include "fcntl.h"
4
5 void test7(void)
6 {
7     FILE * fp;
8     int len;
9     char cmd[50]; 
10     
11     fp = popen("/usr/bin/gnuplot","w");
12     if (fp == NULL) {
13         fprintf(stderr,"Problems\n");
14         return;
15     }
16
17     while(1) {
18         printf("Input command:>");
19         fflush(stdout);
20         gets(cmd);
21         printf("comand is %s\n",cmd);
22         if((len = strlen(cmd)) > 1) {
23             fputs(cmd,fp);
24             fputc('\n',fp);
25             fflush(fp);
26         } else
27             break;
28     }
29     printf(" close status = %d\n",pclose(fp));
30 }
31
32
33
34 void test6(void)
35 {
36
37     FILE *fp;
38     int count; float quant; char units[21], item[21];
39     int i;
40     
41     fp = fopen("/tmp/xxeicxx","w+");
42     fputs("2 quarts of oil\n"
43           "-12.8 degrees Celsius\n"
44           "lots of luck\n"
45           "10.0LBS       of\n"
46           "dirt\n"
47           "100ergs of energy",
48           fp);
49     fseek(fp,0L,SEEK_SET);
50     i = 0;
51     while(!feof(fp) && i < 10) {
52         units[0] = item[0] ='\0';
53         count = fscanf(fp,"%f%20s of %20s",&quant, units, item);
54         fscanf(fp,"%*[^\n]");
55         printf("count = [%d]  quant = [%g] units = [%s] item = [%s]\n",
56                count,quant,units,item);
57        ++i;
58     }
59     fclose(fp);
60
61 }
62
63
64
65 void test5(void)
66 {
67     fprintf(stdout,"%s = %b\n","binary 100", 100);
68     fprintf(stdout,"|%!15.2f|\n", 13.3333);
69 }
70
71 void test4(void)
72 {
73     int i;
74     char *buf = "Hello world Hello world Hello world Hello world\n";
75     for(i=0;buf[i] != '\0'; ++i)
76         fputc(buf[i],stdout);
77
78     fputs(buf,stdout);
79     
80 }
81
82 int main(void)
83 {
84     test6();
85     test5();
86     test4();
87     return 0;
88 }
89
90
91
92
93
94
95
96