c程序不能输出空格
-
- 帖子: 23
- 注册时间: 2007-11-30 18:06
c程序不能输出空格
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<unistd.h>
#define maxsize 100
int main()
{
int fd,size,len;
char buf1[maxsize],buf2[10];
printf("Please input buf1:");
scanf("%s",buf1);
len=strlen(buf1);
if((fd=open("hello",O_CREAT|O_RDWR|O_TRUNC,0666))<0)
{
perror("Open wrong:");
exit(0);
}
else
printf("open double:\n");
if((size=write(fd,buf1,len))<0)
{
perror("write wong:");
exit(1);
}
else
printf("Write double\n");
lseek(fd,0,SEEK_SET);
if((size=read(fd,buf2,10))<0)
{
perror("Read wrong");
exit(0);
}
else
{
printf("read double\n");
printf("ten chars are %s\n",buf2);
}
if(close(fd)<0)
{
perror("Close double wrong");
exit(1);
}
else
printf("Close double:\n");
exit(0);
}
文件保存为 ss.c
:~$ ./ss
Please input buf1:ni shi shui a haha
open double:
Write double
read double
ten chars are niP�H:��
Close double:
输入字符串后不能输出其中的空格
望高手指教!
#include<fcntl.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<unistd.h>
#define maxsize 100
int main()
{
int fd,size,len;
char buf1[maxsize],buf2[10];
printf("Please input buf1:");
scanf("%s",buf1);
len=strlen(buf1);
if((fd=open("hello",O_CREAT|O_RDWR|O_TRUNC,0666))<0)
{
perror("Open wrong:");
exit(0);
}
else
printf("open double:\n");
if((size=write(fd,buf1,len))<0)
{
perror("write wong:");
exit(1);
}
else
printf("Write double\n");
lseek(fd,0,SEEK_SET);
if((size=read(fd,buf2,10))<0)
{
perror("Read wrong");
exit(0);
}
else
{
printf("read double\n");
printf("ten chars are %s\n",buf2);
}
if(close(fd)<0)
{
perror("Close double wrong");
exit(1);
}
else
printf("Close double:\n");
exit(0);
}
文件保存为 ss.c
:~$ ./ss
Please input buf1:ni shi shui a haha
open double:
Write double
read double
ten chars are niP�H:��
Close double:
输入字符串后不能输出其中的空格
望高手指教!
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
-
- 帖子: 23
- 注册时间: 2007-11-30 18:06
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
-
- 帖子: 23
- 注册时间: 2007-11-30 18:06
-
- 帖子: 23
- 注册时间: 2007-11-30 18:06
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系: