任何人都可以HELLP我,因爲我不知道什麼是錯的我覺得我做錯了什麼。在Makefile的Cuz着運行它,我得到錯誤Ç編程的Makefile在Linux
方案:drevoProcesov.c`
#include <sys/types.h>`
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>`
void izpis()
{
printf("PID: %d PPID: %d \n", getpid(), getppid());
}
int main(int argc, char *argv[])
{
/*levo*/
if(fork()==0)
{
if(fork()==0)
{
if(fork()==0)
{
izpis();
exit(0);
}
else
{
wait(0);
izpis();
}
exit(0);
}
else
{
wait(0);
wait(0);
wait(0);
izpis();
}
}
/*desno*/
else
{
wait(0);
if(fork()==0)
{
if(fork()==0)
{
izpis();
exit(0);
}
else
{
wait(0);
if(fork()==0)
{
izpis();
exit(0);
}
else
{
wait(0);
if(fork()==0)
{
izpis();
exit(0);
}
else
{
wait(0);
izpis();
}
}
}
exit(0);
}
else
{
wait(0);
izpis();
}
}
return 0;
}
MAKEFILE
CC=gcc
LDFLAGS=-lm -g3 -lpthread -Wall
TARGET=drevoProcesov
all: $(TARGET)
clean:
rm -rf $(TARGET)
rm -rf *.o
THIS IS的錯誤,我得到:drevoProcesov。 Ç
./drevoProcesov.c: line 7: syntax error near unexpected token `('
./drevoProcesov.c: line 7: `void izpis()'
PROGRAM 2 vsotast.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int *vsota;
int main(int argc,char *argv[]) {
if (argc != 2) {
printf("Napaka v podajanju argumentov!\nPrimer: ./vsotast 5\n");
return -1;
}
int n = atoi(argv[1]);
vsota = (int *)malloc(sizeof(int));
*vsota = 0;
int ret;
for (int i=0; i<n; i++)
{
ret = fork();
if (ret== 0) {
*vsota = (*vsota + (i+1));
//printf("VSOTA: %d; I+1: %d\n",*vsota, i+1);
/*if (i == n-1)
printf("Vsota, ki so jo izračunali sinovi: %d\n", *vsota);*/
exit(0);
} else {
wait(&ret);
}
}
int sum = ((n*(1+n))/(2));
printf("Vsota, ki so jo izračunali sinovi: %d\n", *vsota);
printf("Vsota, ki jo izračunal oce: %d\n",sum);
free(vsota);
return 0;
}
MAKEFILE 2
CC = gcc
LDFLAGS = -lm -g3 -lpthread -Wall
CFLAGS = -g
TARGET = vsotast
all: $(TARGET)
clean:
rm -rf $(TARGET)
rm -rf *.o
THIS IS ERROR我獲得:vsotast.c
gcc -g -lm -g3 -lpthread -Wall vsotast.c -o vsotast
vsotast.c: In function ‘main’:
vsotast.c:22:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i=0; i<n; i++)
^
vsotast.c:22:4: note: use option -std=c99 or -std=gnu99 to compile your code
字符是你的代碼的一部分,還是他們是複製粘貼錯誤? – cdhowie