C: Interpret gcc output and numbres












-2















I have written a C program which produces the following output, when running gcc on a Linux VM on Windows:



Error message:
https://i.stack.imgur.com/P91ZT.jpg



However, the number of "{ and }" should be correct, so that I do not understand why the compiler complains about this. Also I am using k and random after declaring them, how can I get rid of the warnings?



Thank you for your help!



#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
# include <getopt.h>
#include <stdbool.h>

int main(int argc, char ** argv)
{
int opt=0;
//Parameter:
//boolean random:
// typdef enum {false, true} bool;
bool random=false;
//Zahl zu der gezaehlt werden soll: k
int k=10;
//Zahl der Kindprozesse, die erzeugt werden sollen: N
int n=1;
//Parsieren der Kommandozeilenparameter:
while ((opt = getopt(argc, argv, "nt:")) != -1)
{
switch (opt)
{
case 'k':
k = atoi(optarg);
break;
case 'n':
n = atoi(optarg);
break;
case 'r':
random=true;
default: /* '?' */
printf("%s", "No valid parameters.");
exit(EXIT_FAILURE);
}
}
//Erzeugen von n Kindprozessen:
int zaehlerprozesse=0;
while(zaehlerprozesse<n)
{
fork();
zaehlerprozesse++;
}
if(//TODO list)
{
//Kindprozess liegt vor
int zaehler=1;
char ausgabe[256]= {0};
int zaehlen=k;
//Umgehen mit random:
if(random==true)
{
srand((unsigned) time(&t));
int help=rand()%(k*0.5);
//0 oder 1 um zu bestimmen, ob addieren oder substrahieren:
int luck=rand()%1;
if(luck==0)
{
zaehlen=zaehlen-help;
}
else
{
zaehlen=zaehlen+help;
}
}
while(zaehler<=zaehlen)
{
int pid=getpid();
int ppid=getppid();
sprintf(ausgabe, "%d %c %d %c %dn", pid,' ', ppid,' ',zaehler);
write(STDOUT_FILENO, ausgabe, strlen(ausgabe));
sleep(1);
zaehler++;
}
exit((getpid()+k)%100);
}
else
{
//Elternprozess liegt vor
time_t curtime;
time(&curtime);
printf("Start: %s", ctime(&curtime));

}
int exitcode=0;
//TODO bestimmen wie man auf alle aus der Liste wartet:
wait(&exitcode);
//exitcode to String casten:
char str[24];
sprintf(str, "Exit-Code: %dn",WEXITSTATUS(exitcode));
//Ausgabe des Exitcodes:
write(STDOUT_FILENO, str, strlen(str));
time_t curtime;
time(&curtime);
printf("Ende: %sn", ctime(&curtime));
return 0;
}









share|improve this question




















  • 1





    Please post a Minimal, Complete, and Verifiable example. In fact, just the act of trying to make an MCVE (i.e. removing one line or block at a time while making sure this bug still happens, will most likely reveal to you where the syntax error is.

    – David Grayson
    Nov 22 '18 at 7:58













  • if(//TODO list) Did you forget to replace some todo?

    – Mathieu
    Nov 22 '18 at 7:59






  • 2





    Why do you post text as image? Please don't post text as image.

    – Kamil Cuk
    Nov 22 '18 at 8:00






  • 1





    The error says the exact line where it is. It says what it is (not about parens, about what’s missing before that paren). Syntax highlighting shows what’s happening. There’s even a comment saying something’s missing. And MCVE doesn’t help much when fixing syntax errors, looking at the code does.

    – Sami Kuhmonen
    Nov 22 '18 at 8:01
















-2















I have written a C program which produces the following output, when running gcc on a Linux VM on Windows:



Error message:
https://i.stack.imgur.com/P91ZT.jpg



However, the number of "{ and }" should be correct, so that I do not understand why the compiler complains about this. Also I am using k and random after declaring them, how can I get rid of the warnings?



Thank you for your help!



#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
# include <getopt.h>
#include <stdbool.h>

int main(int argc, char ** argv)
{
int opt=0;
//Parameter:
//boolean random:
// typdef enum {false, true} bool;
bool random=false;
//Zahl zu der gezaehlt werden soll: k
int k=10;
//Zahl der Kindprozesse, die erzeugt werden sollen: N
int n=1;
//Parsieren der Kommandozeilenparameter:
while ((opt = getopt(argc, argv, "nt:")) != -1)
{
switch (opt)
{
case 'k':
k = atoi(optarg);
break;
case 'n':
n = atoi(optarg);
break;
case 'r':
random=true;
default: /* '?' */
printf("%s", "No valid parameters.");
exit(EXIT_FAILURE);
}
}
//Erzeugen von n Kindprozessen:
int zaehlerprozesse=0;
while(zaehlerprozesse<n)
{
fork();
zaehlerprozesse++;
}
if(//TODO list)
{
//Kindprozess liegt vor
int zaehler=1;
char ausgabe[256]= {0};
int zaehlen=k;
//Umgehen mit random:
if(random==true)
{
srand((unsigned) time(&t));
int help=rand()%(k*0.5);
//0 oder 1 um zu bestimmen, ob addieren oder substrahieren:
int luck=rand()%1;
if(luck==0)
{
zaehlen=zaehlen-help;
}
else
{
zaehlen=zaehlen+help;
}
}
while(zaehler<=zaehlen)
{
int pid=getpid();
int ppid=getppid();
sprintf(ausgabe, "%d %c %d %c %dn", pid,' ', ppid,' ',zaehler);
write(STDOUT_FILENO, ausgabe, strlen(ausgabe));
sleep(1);
zaehler++;
}
exit((getpid()+k)%100);
}
else
{
//Elternprozess liegt vor
time_t curtime;
time(&curtime);
printf("Start: %s", ctime(&curtime));

}
int exitcode=0;
//TODO bestimmen wie man auf alle aus der Liste wartet:
wait(&exitcode);
//exitcode to String casten:
char str[24];
sprintf(str, "Exit-Code: %dn",WEXITSTATUS(exitcode));
//Ausgabe des Exitcodes:
write(STDOUT_FILENO, str, strlen(str));
time_t curtime;
time(&curtime);
printf("Ende: %sn", ctime(&curtime));
return 0;
}









share|improve this question




















  • 1





    Please post a Minimal, Complete, and Verifiable example. In fact, just the act of trying to make an MCVE (i.e. removing one line or block at a time while making sure this bug still happens, will most likely reveal to you where the syntax error is.

    – David Grayson
    Nov 22 '18 at 7:58













  • if(//TODO list) Did you forget to replace some todo?

    – Mathieu
    Nov 22 '18 at 7:59






  • 2





    Why do you post text as image? Please don't post text as image.

    – Kamil Cuk
    Nov 22 '18 at 8:00






  • 1





    The error says the exact line where it is. It says what it is (not about parens, about what’s missing before that paren). Syntax highlighting shows what’s happening. There’s even a comment saying something’s missing. And MCVE doesn’t help much when fixing syntax errors, looking at the code does.

    – Sami Kuhmonen
    Nov 22 '18 at 8:01














-2












-2








-2








I have written a C program which produces the following output, when running gcc on a Linux VM on Windows:



Error message:
https://i.stack.imgur.com/P91ZT.jpg



However, the number of "{ and }" should be correct, so that I do not understand why the compiler complains about this. Also I am using k and random after declaring them, how can I get rid of the warnings?



Thank you for your help!



#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
# include <getopt.h>
#include <stdbool.h>

int main(int argc, char ** argv)
{
int opt=0;
//Parameter:
//boolean random:
// typdef enum {false, true} bool;
bool random=false;
//Zahl zu der gezaehlt werden soll: k
int k=10;
//Zahl der Kindprozesse, die erzeugt werden sollen: N
int n=1;
//Parsieren der Kommandozeilenparameter:
while ((opt = getopt(argc, argv, "nt:")) != -1)
{
switch (opt)
{
case 'k':
k = atoi(optarg);
break;
case 'n':
n = atoi(optarg);
break;
case 'r':
random=true;
default: /* '?' */
printf("%s", "No valid parameters.");
exit(EXIT_FAILURE);
}
}
//Erzeugen von n Kindprozessen:
int zaehlerprozesse=0;
while(zaehlerprozesse<n)
{
fork();
zaehlerprozesse++;
}
if(//TODO list)
{
//Kindprozess liegt vor
int zaehler=1;
char ausgabe[256]= {0};
int zaehlen=k;
//Umgehen mit random:
if(random==true)
{
srand((unsigned) time(&t));
int help=rand()%(k*0.5);
//0 oder 1 um zu bestimmen, ob addieren oder substrahieren:
int luck=rand()%1;
if(luck==0)
{
zaehlen=zaehlen-help;
}
else
{
zaehlen=zaehlen+help;
}
}
while(zaehler<=zaehlen)
{
int pid=getpid();
int ppid=getppid();
sprintf(ausgabe, "%d %c %d %c %dn", pid,' ', ppid,' ',zaehler);
write(STDOUT_FILENO, ausgabe, strlen(ausgabe));
sleep(1);
zaehler++;
}
exit((getpid()+k)%100);
}
else
{
//Elternprozess liegt vor
time_t curtime;
time(&curtime);
printf("Start: %s", ctime(&curtime));

}
int exitcode=0;
//TODO bestimmen wie man auf alle aus der Liste wartet:
wait(&exitcode);
//exitcode to String casten:
char str[24];
sprintf(str, "Exit-Code: %dn",WEXITSTATUS(exitcode));
//Ausgabe des Exitcodes:
write(STDOUT_FILENO, str, strlen(str));
time_t curtime;
time(&curtime);
printf("Ende: %sn", ctime(&curtime));
return 0;
}









share|improve this question
















I have written a C program which produces the following output, when running gcc on a Linux VM on Windows:



Error message:
https://i.stack.imgur.com/P91ZT.jpg



However, the number of "{ and }" should be correct, so that I do not understand why the compiler complains about this. Also I am using k and random after declaring them, how can I get rid of the warnings?



Thank you for your help!



#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
# include <getopt.h>
#include <stdbool.h>

int main(int argc, char ** argv)
{
int opt=0;
//Parameter:
//boolean random:
// typdef enum {false, true} bool;
bool random=false;
//Zahl zu der gezaehlt werden soll: k
int k=10;
//Zahl der Kindprozesse, die erzeugt werden sollen: N
int n=1;
//Parsieren der Kommandozeilenparameter:
while ((opt = getopt(argc, argv, "nt:")) != -1)
{
switch (opt)
{
case 'k':
k = atoi(optarg);
break;
case 'n':
n = atoi(optarg);
break;
case 'r':
random=true;
default: /* '?' */
printf("%s", "No valid parameters.");
exit(EXIT_FAILURE);
}
}
//Erzeugen von n Kindprozessen:
int zaehlerprozesse=0;
while(zaehlerprozesse<n)
{
fork();
zaehlerprozesse++;
}
if(//TODO list)
{
//Kindprozess liegt vor
int zaehler=1;
char ausgabe[256]= {0};
int zaehlen=k;
//Umgehen mit random:
if(random==true)
{
srand((unsigned) time(&t));
int help=rand()%(k*0.5);
//0 oder 1 um zu bestimmen, ob addieren oder substrahieren:
int luck=rand()%1;
if(luck==0)
{
zaehlen=zaehlen-help;
}
else
{
zaehlen=zaehlen+help;
}
}
while(zaehler<=zaehlen)
{
int pid=getpid();
int ppid=getppid();
sprintf(ausgabe, "%d %c %d %c %dn", pid,' ', ppid,' ',zaehler);
write(STDOUT_FILENO, ausgabe, strlen(ausgabe));
sleep(1);
zaehler++;
}
exit((getpid()+k)%100);
}
else
{
//Elternprozess liegt vor
time_t curtime;
time(&curtime);
printf("Start: %s", ctime(&curtime));

}
int exitcode=0;
//TODO bestimmen wie man auf alle aus der Liste wartet:
wait(&exitcode);
//exitcode to String casten:
char str[24];
sprintf(str, "Exit-Code: %dn",WEXITSTATUS(exitcode));
//Ausgabe des Exitcodes:
write(STDOUT_FILENO, str, strlen(str));
time_t curtime;
time(&curtime);
printf("Ende: %sn", ctime(&curtime));
return 0;
}






c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 8:47









P.W

12.5k3844




12.5k3844










asked Nov 22 '18 at 7:55









SQLLearnerSQLLearner

85




85








  • 1





    Please post a Minimal, Complete, and Verifiable example. In fact, just the act of trying to make an MCVE (i.e. removing one line or block at a time while making sure this bug still happens, will most likely reveal to you where the syntax error is.

    – David Grayson
    Nov 22 '18 at 7:58













  • if(//TODO list) Did you forget to replace some todo?

    – Mathieu
    Nov 22 '18 at 7:59






  • 2





    Why do you post text as image? Please don't post text as image.

    – Kamil Cuk
    Nov 22 '18 at 8:00






  • 1





    The error says the exact line where it is. It says what it is (not about parens, about what’s missing before that paren). Syntax highlighting shows what’s happening. There’s even a comment saying something’s missing. And MCVE doesn’t help much when fixing syntax errors, looking at the code does.

    – Sami Kuhmonen
    Nov 22 '18 at 8:01














  • 1





    Please post a Minimal, Complete, and Verifiable example. In fact, just the act of trying to make an MCVE (i.e. removing one line or block at a time while making sure this bug still happens, will most likely reveal to you where the syntax error is.

    – David Grayson
    Nov 22 '18 at 7:58













  • if(//TODO list) Did you forget to replace some todo?

    – Mathieu
    Nov 22 '18 at 7:59






  • 2





    Why do you post text as image? Please don't post text as image.

    – Kamil Cuk
    Nov 22 '18 at 8:00






  • 1





    The error says the exact line where it is. It says what it is (not about parens, about what’s missing before that paren). Syntax highlighting shows what’s happening. There’s even a comment saying something’s missing. And MCVE doesn’t help much when fixing syntax errors, looking at the code does.

    – Sami Kuhmonen
    Nov 22 '18 at 8:01








1




1





Please post a Minimal, Complete, and Verifiable example. In fact, just the act of trying to make an MCVE (i.e. removing one line or block at a time while making sure this bug still happens, will most likely reveal to you where the syntax error is.

– David Grayson
Nov 22 '18 at 7:58







Please post a Minimal, Complete, and Verifiable example. In fact, just the act of trying to make an MCVE (i.e. removing one line or block at a time while making sure this bug still happens, will most likely reveal to you where the syntax error is.

– David Grayson
Nov 22 '18 at 7:58















if(//TODO list) Did you forget to replace some todo?

– Mathieu
Nov 22 '18 at 7:59





if(//TODO list) Did you forget to replace some todo?

– Mathieu
Nov 22 '18 at 7:59




2




2





Why do you post text as image? Please don't post text as image.

– Kamil Cuk
Nov 22 '18 at 8:00





Why do you post text as image? Please don't post text as image.

– Kamil Cuk
Nov 22 '18 at 8:00




1




1





The error says the exact line where it is. It says what it is (not about parens, about what’s missing before that paren). Syntax highlighting shows what’s happening. There’s even a comment saying something’s missing. And MCVE doesn’t help much when fixing syntax errors, looking at the code does.

– Sami Kuhmonen
Nov 22 '18 at 8:01





The error says the exact line where it is. It says what it is (not about parens, about what’s missing before that paren). Syntax highlighting shows what’s happening. There’s even a comment saying something’s missing. And MCVE doesn’t help much when fixing syntax errors, looking at the code does.

– Sami Kuhmonen
Nov 22 '18 at 8:01












1 Answer
1






active

oldest

votes


















1














I can see three issues in the code.





  • if(//TODO list) Because of the comment marker // the closing parenthesis ) for the if is missing and also there is no condition for it.


  • srand((unsigned) time(&t)); t is undeclared here.


  • int help=rand()%(k*0.5);. You are using a double (k*0.5) as an operand of %






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426202%2fc-interpret-gcc-output-and-numbres%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I can see three issues in the code.





    • if(//TODO list) Because of the comment marker // the closing parenthesis ) for the if is missing and also there is no condition for it.


    • srand((unsigned) time(&t)); t is undeclared here.


    • int help=rand()%(k*0.5);. You are using a double (k*0.5) as an operand of %






    share|improve this answer




























      1














      I can see three issues in the code.





      • if(//TODO list) Because of the comment marker // the closing parenthesis ) for the if is missing and also there is no condition for it.


      • srand((unsigned) time(&t)); t is undeclared here.


      • int help=rand()%(k*0.5);. You are using a double (k*0.5) as an operand of %






      share|improve this answer


























        1












        1








        1







        I can see three issues in the code.





        • if(//TODO list) Because of the comment marker // the closing parenthesis ) for the if is missing and also there is no condition for it.


        • srand((unsigned) time(&t)); t is undeclared here.


        • int help=rand()%(k*0.5);. You are using a double (k*0.5) as an operand of %






        share|improve this answer













        I can see three issues in the code.





        • if(//TODO list) Because of the comment marker // the closing parenthesis ) for the if is missing and also there is no condition for it.


        • srand((unsigned) time(&t)); t is undeclared here.


        • int help=rand()%(k*0.5);. You are using a double (k*0.5) as an operand of %







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 8:02









        P.WP.W

        12.5k3844




        12.5k3844






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426202%2fc-interpret-gcc-output-and-numbres%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen