0

Hello I tried to get a external parameters to my main. But somehow the compiler gcc shows me weird problems I have not encountered them and did not find a solution. I would be happy if you help me understand the problems and fix them.

code-

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

 main(int argc, char** argv[])
 {
 int i;
char temp[99];

for (i=0; i < argc/2 ; i++)
{       
    temp = argv[i];   
    argv[i] = argv[argc-i-1];    
    argv[argc-i-1] = temp;  
}

for(i = 0; i < argc ; i++)
{
    printf("%s",temp[i]);
}
return(0);
 }

errores

error: incompatible types in assignment

warning: assignment from incompatible pointer type

  • Please don't assign values to `argv` like that. You technically can - the compiler won't stop you - but you're not supposed to. – cf- Apr 05 '14 at 19:01
  • @computerfreak: Actually, that's a myth. The standard fully supports changing argc, argv, the pointers argv points to and the strings themselves. – Deduplicator Apr 05 '14 at 19:25
  • @Deduplicator My understanding is that [that's mainly for historical reasons](http://stackoverflow.com/questions/20558418/why-is-argc-not-a-constant/20558441#20558441). I still wouldn't consider it a good idea. – cf- Apr 05 '14 at 19:28
  • @computerfreak: Well, now that they are malleable, there is no reason not to use that feature, even if it might have made sense not to allow it. But that train has long left the station. – Deduplicator Apr 05 '14 at 19:37

1 Answers1

2

Bad prototype for main: Use int main(), int main(int argc, char** argv) or something compatible.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118