该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
但我发现windows下的头文件在linux下不能用,是很正常的!
批量编译GCC的C源程序:
#include
#include
#include
#include
#include
char *c="c";
char *cpp="cpp";
char *dot=".";
char *dotdot="..";
char *getfilename(char *fullname){
char retname[256];
char *q=rindex(fullname,'.'); //从p中找到.出现的位置,此后q=".bin"
strncpy(retname,fullname,q-fullname); //把p与q之间的字符复制给s,此后s="234"
retname[q-fullname]='\0'; //在s数字字符串的末尾加上null
return retname;
}
void do_search_dir(char *path) {
DIR *dir;
char fullpath[1024],currfile[1024];
struct dirent *s_dir;
struct stat file_stat;
strcpy(fullpath,path);
dir=opendir(fullpath);
while ((s_dir=readdir(dir))!=NULL) {
if ((strcmp(s_dir->d_name,dot)==0)||(strcmp(s_dir->d_name,dotdot)==0))
continue;
sprintf(currfile,"%s/%s",fullpath,s_dir->d_name);
stat(currfile,&file_stat);
if (S_ISDIR(file_stat.st_mode))
do_search_dir(currfile);
else if(strstr(currfile+2,dot))
{
char gcc[512]="gcc ";
char o[256]=" -o ";
char *p=currfile;
while(*p)p++;
while(p>currfile && *p!='.')p--;
if (p!=currfile)p++;
strcat(gcc,currfile);
strcat(o,getfilename(currfile));
if((p-currfile+1==strlen(currfile) && strncmp(p,c,1)==0) || (p-currfile+3==strlen(currfile) && strncmp(p,cpp,3)==0))
{
sprintf(currfile,"%s%s",gcc,o);
system(currfile);
}
}
}
closedir(dir);
}
int main() {
do_search_dir(dot);
return 0;
}