why? 
Author Message
 why?

hi,
why that:
 In function `main':
17: parse error before `comando'
 At top level:
22: parse error before string constant
22: warning: data definition has no type or storage class
23: parse error before `+'
23: warning: data definition has no type or storage class
24: parse error before `+'
25: parse error before `+'
26: parse error before `+'

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char * argv[]);

int main(int argc, char * argv[]) {
        //stampo errore se nn specifica l'argomento
        if (argc!=2) {
                printf("Err: sintassi: diprova1 [file senza .asc]\n");
                return -1;
        }

        //char *prova= (char *) malloc (10);

        if ( !(char *comando = (char *) malloc( (strlen(argv[1])*2) + 15 )
)) {

                printf("Non riesco ad allocare %d bytes in memoria
(malloc)\n",strlen(argv[1])*2+15);
                return -2;
        }

        strcpy(comando, "diprova1 \0");
        strcpy(comando+9,argv[1]);
        strcpy(comando+strlen(argv[1])+10, " \0");
        strcpy(comando+strlen(argv[1])+11, argv[1]);
        strcpy(comando+strlen(argv[1])*2+11,".asc\0");

        if (system(comando) == -1) {
                printf("errore %d in system()\n", errno);
                return -3;
        }
        return 0;

Quote:
}



Sat, 02 Apr 2005 23:47:32 GMT  
 why?

Quote:
> hi,
> why that:
>  In function `main':
> 17: parse error before `comando'
>  At top level:
> 22: parse error before string constant
> 22: warning: data definition has no type or storage class
> 23: parse error before `+'
> 23: warning: data definition has no type or storage class
> 24: parse error before `+'
> 25: parse error before `+'
> 26: parse error before `+'
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include <errno.h>
> int main(int argc, char * argv[]);
> int main(int argc, char * argv[]) {
>         //stampo errore se nn specifica l'argomento
>         if (argc!=2) {
>                 printf("Err: sintassi: diprova1 [file senza .asc]\n");
>                 return -1;
>         }

>         //char *prova= (char *) malloc (10);
>         if ( !(char *comando = (char *) malloc( (strlen(argv[1])*2) + 15 )

                 ^^^^^^^^^^^^^
You're trying to define a new variable in the middle of an expression.
C's syntax rules don't allow that. You can instead just define
char *comando; at the top of main() and just write comando instead of
char *comando here.

I did not bother to comment on the actual program logic, I just pointed
out the syntax error.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"'It can be easily shown that' means 'I saw a proof of this once (which I didn't
understand) which I can no longer remember'."
   - A maths teacher



Sat, 02 Apr 2005 23:49:25 GMT  
 why?
right!

thanks.

Quote:


>> hi,
>> why that:
>>  In function `main':
>> 17: parse error before `comando'
>>  At top level:
>> 22: parse error before string constant
>> 22: warning: data definition has no type or storage class
>> 23: parse error before `+'
>> 23: warning: data definition has no type or storage class
>> 24: parse error before `+'
>> 25: parse error before `+'
>> 26: parse error before `+'

>> #include <stdio.h>
>> #include <string.h>
>> #include <stdlib.h>
>> #include <errno.h>

>> int main(int argc, char * argv[]);

>> int main(int argc, char * argv[]) {
>>         //stampo errore se nn specifica l'argomento
>>         if (argc!=2) {
>>                 printf("Err: sintassi: diprova1 [file senza .asc]\n");
>>                 return -1;
>>         }

>>         //char *prova= (char *) malloc (10);

>>         if ( !(char *comando = (char *) malloc( (strlen(argv[1])*2) + 15
>>         )
>                  ^^^^^^^^^^^^^
> You're trying to define a new variable in the middle of an expression.
> C's syntax rules don't allow that. You can instead just define
> char *comando; at the top of main() and just write comando instead of
> char *comando here.

> I did not bother to comment on the actual program logic, I just pointed
> out the syntax error.



Sun, 03 Apr 2005 00:11:09 GMT  
 why?
Quote:

> right!

> thanks.



>>>hi,
>>>why that:
>>> In function `main':
>>>17: parse error before `comando'
>>> At top level:
>>>22: parse error before string constant
>>>22: warning: data definition has no type or storage class
>>>23: parse error before `+'
>>>23: warning: data definition has no type or storage class
>>>24: parse error before `+'
>>>25: parse error before `+'
>>>26: parse error before `+'

>>>#include <stdio.h>
>>>#include <string.h>
>>>#include <stdlib.h>
>>>#include <errno.h>

>>>int main(int argc, char * argv[]);

>>>int main(int argc, char * argv[]) {
>>>        //stampo errore se nn specifica l'argomento
>>>        if (argc!=2) {
>>>                printf("Err: sintassi: diprova1 [file senza .asc]\n");
>>>                return -1;
>>>        }

>>>        //char *prova= (char *) malloc (10);

>>>        if ( !(char *comando = (char *) malloc( (strlen(argv[1])*2) + 15
>>>        )

>>                 ^^^^^^^^^^^^^
>>You're trying to define a new variable in the middle of an expression.
>>C's syntax rules don't allow that. You can instead just define
>>char *comando; at the top of main() and just write comando instead of
>>char *comando here.

>>I did not bother to comment on the actual program logic, I just pointed
>>out the syntax error.

why are you writing out the prototype for main?


Sun, 03 Apr 2005 00:59:22 GMT  
 why?


Quote:

> > right!

> > thanks.



> >>>hi,
> >>>why that:
> >>> In function `main':
> >>>17: parse error before `comando'
> >>> At top level:
> >>>22: parse error before string constant
> >>>22: warning: data definition has no type or storage class
> >>>23: parse error before `+'
> >>>23: warning: data definition has no type or storage class
> >>>24: parse error before `+'
> >>>25: parse error before `+'
> >>>26: parse error before `+'

> >>>#include <stdio.h>
> >>>#include <string.h>
> >>>#include <stdlib.h>
> >>>#include <errno.h>

> >>>int main(int argc, char * argv[]);

> >>>int main(int argc, char * argv[]) {
> >>>        //stampo errore se nn specifica l'argomento
> >>>        if (argc!=2) {
> >>>                printf("Err: sintassi: diprova1 [file senza .asc]\n");
> >>>                return -1;
> >>>        }

> >>>        //char *prova= (char *) malloc (10);

> >>>        if ( !(char *comando = (char *) malloc( (strlen(argv[1])*2) +
15
> >>>        )

> >>                 ^^^^^^^^^^^^^
> >>You're trying to define a new variable in the middle of an expression.
> >>C's syntax rules don't allow that. You can instead just define
> >>char *comando; at the top of main() and just write comando instead of
> >>char *comando here.

> >>I did not bother to comment on the actual program logic, I just pointed
> >>out the syntax error.

> why are you writing out the prototype for main?

Whats wrong with that?


Sun, 03 Apr 2005 01:56:49 GMT  
 why?

(Huge snip!)

Quote:
>> why are you writing out the prototype for main?
> Whats wrong with that?

Nothing, but it's not needed, as the definition of main will also
prototype it.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
   - Teemu Kerola



Sun, 03 Apr 2005 02:02:52 GMT  
 why?



Quote:



> (Huge snip!)

> >> why are you writing out the prototype for main?

> > Whats wrong with that?

> Nothing, but it's not needed, as the definition of main will also
> prototype it.

I know its not needed, but it doesnt do any harm sitting there. :-)

Quote:
> --

> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
> | http://www.helsinki.fi/~palaste       W++ B OP+                     |
> \----------------------------------------- Finland rules! ------------/
> "And according to Occam's Toothbrush, we only need to optimise the most
frequent
> instructions."
>    - Teemu Kerola



Sun, 03 Apr 2005 02:05:26 GMT  
 why?

Quote:



>> > Whats wrong with that?

>> Nothing, but it's not needed, as the definition of main will also
>> prototype it.
> I know its not needed, but it doesnt do any harm sitting there. :-)

Wasn't that basically what I just said?

This program is completely legal C code:

int main(int argc, char *argv);
int main(int argc, char *argv);
int main(int argc, char *argv);
int main(int argc, char *argv) {
  return 0;

Quote:
}

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"As we all know, the hardware for the PC is great, but the software sucks."
   - Petro Tyschtschenko


Sun, 03 Apr 2005 02:09:21 GMT  
 why?



Quote:




> >> > Whats wrong with that?

> >> Nothing, but it's not needed, as the definition of main will also
> >> prototype it.

> > I know its not needed, but it doesnt do any harm sitting there. :-)

> Wasn't that basically what I just said?

> This program is completely legal C code:

> int main(int argc, char *argv);
> int main(int argc, char *argv);
> int main(int argc, char *argv);
> int main(int argc, char *argv) {
>   return 0;
> }

> --

> | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
> | http://www.helsinki.fi/~palaste       W++ B OP+                     |
> \----------------------------------------- Finland rules! ------------/
> "As we all know, the hardware for the PC is great, but the software
sucks."
>    - Petro Tyschtschenko

Forget it


Sun, 03 Apr 2005 02:27:25 GMT  
 why?
Quote:





>>>>Whats wrong with that?

>>>Nothing, but it's not needed, as the definition of main will also
>>>prototype it.

>>I know its not needed, but it doesnt do any harm sitting there. :-)

> Wasn't that basically what I just said?

> This program is completely legal C code:

> int main(int argc, char *argv);
> int main(int argc, char *argv);
> int main(int argc, char *argv);
> int main(int argc, char *argv) {
>   return 0;
> }

forget i asked :P


Sun, 03 Apr 2005 02:52:39 GMT  
 why?

Quote:


... snip ...

> > why are you writing out the prototype for main?

> Whats wrong with that?

It is totally useless unless you are going to call main
recursively from some other function.  It is one more place to
make a mistake.  You create prototypes for purposes, not for rote.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Sun, 03 Apr 2005 04:36:51 GMT  
 why?

Quote:



>... snip ...

>> > why are you writing out the prototype for main?

>> Whats wrong with that?

>It is totally useless unless you are going to call main
>recursively from some other function.  It is one more place to
>make a mistake.  You create prototypes for purposes, not for rote.

And what is the purpose, even if you are going to call main() recursively?

--Ben

--



Sun, 03 Apr 2005 05:01:42 GMT  
 why?


Quote:




> >... snip ...

> >> > why are you writing out the prototype for main?

> >> Whats wrong with that?

> >It is totally useless unless you are going to call main
> >recursively from some other function.  It is one more place to
> >make a mistake.  You create prototypes for purposes, not for rote.

> And what is the purpose, even if you are going to call main() recursively?

If you call main() from another function, and it is implemented before
main() in the C source file, then it needs a prototype.  But I hope nobody
would ever do this.  I can't think of a good reason to call main() from
another function.

                Dan



Sun, 03 Apr 2005 05:27:10 GMT  
 why?


Quote:







> > >... snip ...

> > >> > why are you writing out the prototype for main?

> > >> Whats wrong with that?

> > >It is totally useless unless you are going to call main
> > >recursively from some other function.  It is one more place to
> > >make a mistake.  You create prototypes for purposes, not for rote.

> > And what is the purpose, even if you are going to call main()
recursively?

> If you call main() from another function, and it is implemented before
> main() in the C source file, then it needs a prototype.  But I hope nobody
> would ever do this.  I can't think of a good reason to call main() from
> another function.

>                 Dan

What I said was 'Whats wrong with that?' Doesnt mean that its illegal, I
just meant whats wrong with that. Somebody might want to call main from
another function, you never know.
Anyways...


Sun, 03 Apr 2005 07:20:16 GMT  
 why?

Quote:

> It is totally useless unless you are going to call main
> recursively from some other function.  

The word "recursively", doesn't belong in that sentence.

--
 pete



Sun, 03 Apr 2005 07:51:54 GMT  
 
 [ 24 post ]  Go to page: [1] [2]

 Relevant Pages 

1. why, Why, WHY

2. Why oh Why can no one help me..

3. Interface IDs - why oh why??

4. Why? Why? Why? ATL Component not registering

5. WHY? WHY? WHY?

6. WHY? WHY? WHY?

7. WHY? WHY? WHY?

8. Alloca... Why and Why not?

9. Noise: Why C, Why VB and when to C++ or even going Visual?

10. realloc(): Why? Why not?

11. Why does .Execute in Command Object slower??Also why is dts faster than Ado??

12. Why This Works? Why This Not Works?

 

 
Powered by phpBB® Forum Software