A question regarding argv

L

Logan

(CODE I)
#include <stdio.h>

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

printf("argc = %d\n", argc);
for(x = 0; x < argc; x++ ) {
printf("argv[%d] = %s.\n", x, argv[x]);
}
return 0;
}


(CODE II)
#include <stdio.h>

int main(int argc, char *argv)
{
int x;

printf("argc = %d\n", argc);
for(x = 0; x < argc; x++ ) {
printf("argv[%d] = %s.\n", x, argv[x]);
}
return 0;
}

CODE I works but CODE II gives segmentation error. Why?
 
C

CBFalconer

Logan said:
(CODE I)
#include <stdio.h>

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

printf("argc = %d\n", argc);
for(x = 0; x < argc; x++ ) {
printf("argv[%d] = %s.\n", x, argv[x]);
}
return 0;
}

(CODE II)
#include <stdio.h>

int main(int argc, char *argv) {
int x;

printf("argc = %d\n", argc);
for(x = 0; x < argc; x++ ) {
printf("argv[%d] = %s.\n", x, argv[x]);
}
return 0;
}

CODE I works but CODE II gives segmentation error. Why?

You want "char **argv".
 
B

Barry Schwarz

(CODE I)
#include <stdio.h>

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

printf("argc = %d\n", argc);
for(x = 0; x < argc; x++ ) {
printf("argv[%d] = %s.\n", x, argv[x]);
}
return 0;
}


(CODE II)
#include <stdio.h>

int main(int argc, char *argv)
{
int x;

printf("argc = %d\n", argc);
for(x = 0; x < argc; x++ ) {
printf("argv[%d] = %s.\n", x, argv[x]);
}
return 0;
}

CODE I works but CODE II gives segmentation error. Why?

Because this is the same code you posted three minutes ago.


Remove del for email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top