跪求编程大神帮我解答下此题~高分悬赏~在线等~急!! 100
1个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 4096
char buf[N];
int main(void)
{
int i, n;
scanf("%d ", &n);
for (i = 0; i < n; i++)
{
FILE *fp;
strcpy(buf, "main(){int ");
fgets(buf + strlen(buf), N, stdin);
strcat(buf, ";");
fgets(buf + strlen(buf), N, stdin);
strcat(buf, ";}");
fp = fopen("tmp.c", "w");
fwrite(buf, 1, strlen(buf), fp);
fclose(fp);
if (system("gcc -o tmp tmp.c 2>tmp.log") == 0)
printf("OK!\n");
else
{
fp = fopen("tmp.log", "r");
fgets(buf, N, fp);
fgets(buf, N, fp);
puts(buf + 9);
fclose(fp);
}
}
return 0;
}
#include <stdlib.h>
#include <string.h>
#define N 4096
char buf[N];
int main(void)
{
int i, n;
scanf("%d ", &n);
for (i = 0; i < n; i++)
{
FILE *fp;
strcpy(buf, "main(){int ");
fgets(buf + strlen(buf), N, stdin);
strcat(buf, ";");
fgets(buf + strlen(buf), N, stdin);
strcat(buf, ";}");
fp = fopen("tmp.c", "w");
fwrite(buf, 1, strlen(buf), fp);
fclose(fp);
if (system("gcc -o tmp tmp.c 2>tmp.log") == 0)
printf("OK!\n");
else
{
fp = fopen("tmp.log", "r");
fgets(buf, N, fp);
fgets(buf, N, fp);
puts(buf + 9);
fclose(fp);
}
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询