12389 sqrt 16
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main (void)
{
char cmd [128];
char buf [128];
int fd;
int n;
int pid;
double num;
if ((fd = open ("test.txt", O_RDONLY)) == -1) {
perror("open");
exit(1);
}
n = read (fd, buf, 128);
printf("%d\n", n);
if (buf [n-1] == '\n')
buf [n-1] = '\0'; /*吃掉换行符*/
printf("%s\n", buf);
sscanf (buf, "%d %s %f", &pid, cmd, &num);
printf("pid=%d, cmd=%s, num=%f", pid, cmd, num);
return (0);
}
beyes@linux-beyes:~/C/pipe> gcc -g -Wall read_test.c -o read_test.exe
read_test.c: In function ‘main’:
read_test.c:26: warning: format ‘%f’ expects type ‘float *’, but argument 5 has type ‘double *’
beyes@linux-beyes:~/C/pipe> ./read_test.exe
14
12389 sqrt 16
pid=12389, cmd=sqrt, num=-0.000000
beyes@linux-beyes:~/C/pipe> ./read_test.exe
14
12389 sqrt 16
pid=12389, cmd=sqrt, num=16.000000
#include "stdio.h"
#include "conio.h"main()
{
printf("The program test print style!\n");
/* 以十进制形式输出带符号整数(正数不输出符号) */
printf("%d\n" , 223);
printf("%d\n" , -232);
printf("\n"); /* 以八进制形式输出无符号整数(不输出前缀O) */
printf("%o\n" , 223);
printf("%o\n" , -232);
printf("\n"); /* 以十六进制形式输出无符号整数(不输出前缀OX) */
printf("%x\n" , 223);
printf("%x\n" , -232);
printf("\n"); /* 以十进制形式输出无符号整数 */
printf("%u\n" , 223);
printf("%u\n" , -232);
printf("\n"); /* 以小数形式输出单、双精度实数 */
printf("%f\n" , 223.11);
printf("%f\n" , 232.11111111);
printf("%f\n" , -223.11);
printf("%f\n" , -232.11111111);
printf("\n"); /* 以指数形式输出单、双精度实数 */
printf("%e\n" , 223.11);
printf("%e\n" , 232.11111111);
printf("%e\n" , -223.11);
printf("%e\n" , -232.11111111);
printf("\n"); /* 以%f%e中较短的输出宽度输出单、双精度实数 */
printf("%g\n" , 223.11);
printf("%g\n" , 232.111111111111);
printf("%g\n" , -223.11);
printf("%g\n" , -232.111111111111);
printf("\n"); /* 输出单个字符 */
printf("%c\n" , 'a');
printf("%c\n" , 97);
printf("\n"); /* 输出单个字符 */
printf("%s\n" , "this is a test!");
printf("%s\n" , "2342o34uo23u");
printf("\n"); getch();
}
#include "stdio.h"
#include "conio.h"main()
{ /* 以十进制形式输出带符号整数(正数不输出符号) */
printf("*%-10d*\n", 223);
printf("*%+10d*\n" , -232);
printf("*%2d*\n" , 223);
printf("*%#d*\n" , -232);
printf("\n");
getch(); /* 以八进制形式输出无符号整数(不输出前缀O) */
printf("*%-10o*\n" , 223);
printf("*%+10o*\n" , -232);
printf("*%o*\n" , 223);
printf("*%#o*\n" , -232);
printf("\n");
getch(); /* 以十六进制形式输出无符号整数(不输出前缀OX) */
printf("$%-10x$\n" , 223);
printf("$%010x$\n" , -232);
printf("$% x$\n" , 223);
printf("$%#x$\n" , -232);
printf("\n");
/* 以十进制形式输出无符号整数 */
printf("%-10u\n" , 223);
printf("%+10u\n" , -232);
printf("% u\n" , 223);
printf("%#u\n" , -232);
printf("\n");
getch(); /* 以小数形式输出单、双精度实数 */
printf("%-10f\n" , 223.11);
printf("%+10f\n" , 232.11111111);
printf("% f\n" , -223.11);
printf("%#f\n" , -232.11111111);
printf("\n");
getch(); /* 以指数形式输出单、双精度实数 */
printf("%-10e\n" , 223.11);
printf("%+10e\n" , 232.11111111);
printf("% e\n" , -223.11);
printf("%#e\n" , -232.11111111);
printf("\n");
getch(); /* 以%f%e中较短的输出宽度输出单、双精度实数 */
printf("%-10g\n" , 223.11);
printf("%+10g\n" , 232.111111111111);
printf("% g\n" , -223.11);
printf("%#g\n" , -232.111111111111);
printf("\n");
getch(); /* 输出单个字符 */
printf("%-10c\n" , 'a');
printf("%+10c\n" , 97);
printf("% c\n" , 'a');
printf("%#c\n" , 97);
printf("\n");
getch(); /* 输出单个字符 */
printf("%-20s\n" , "this is a test!");
printf("%+20s\n" , "2342o34uo23u");
printf("% 20s\n" , "this is a test!");/* 不足补空格 */
printf("%#s\n" , "2342o34uo23u");
printf("\n");
getch();}
#include "stdio.h"
#include "conio.h"main()
{
printf("%.3d\n" , 5555);
getch(); printf("%.3f\n" , 0.88888);
getch(); printf("%.3f\n" , 0.9999);
getch(); printf("%.4s\n" , "this is a test!");
getch();
}
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |