求救 编写C/C++程序 在线等

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:31:33
编写一个C语言程序,用open函数在当前目录下创建一个文件test.txt,然后将数字1~100按顺序写入文件, 之后分别读出第50(从文件开始处计算)、第100个字节处的数字, 并输出该数字到标准输出。然后关闭并删除文件。
还有一个:
首先用shell命令在用户主目录下创建一个文件myfile, 然后用C语言编写一个程序打印出该文件的类型和组权限位, 判断该用户对该文件是否有执行权限。如果没有,请通过chmod函数给它加上执行权限。
还有代码注释
谢谢谢谢谢谢

第一道题:#include<stdlib.h>
#include<stdio.h>
main()
{
FILE *fp;
char ch;
if ((fp=fopen("test.txt","w+"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
int i=1;
for(;i<=100;i++)
{
fprintf(fp,"%d",i);
}
fseek(fp,50L,0);
ch=fgetc(fp);
printf("%c\n",ch);
fseek(fp,100L,0);
ch=fgetc(fp);
printf("%c\n",ch);
fclose(fp);
remove("test.txt");
}
第二道题 新建文件是touch myfile 加入执行权限权限是chmod +x myfile
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#define N_BITS 3
int main(int argc,char*argv[])
{
unsigned int i,mask=0700;
struct stat buff;
static char *perm[]={"---","--x","-w-","-wx&q