-1

I am trying to write a C program in linux. Here's the code:

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

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

  for(i = 0; i < argc; i++)
  {
    printf("%s\n", *argv[i]);
  }

  return 0;
}

gcc keeps giving me the error segmentation fault (core dumped) I'm assuming I have to deference *argv[i] but I don't know. Please help.

Shubham
  • 2,531
  • 3
  • 19
  • 33
and 1
  • 1

1 Answers1

3

char** argv[] should be char** argv or char *argv[]. Then you can do:

int i;
for(i = 0; i < argc; i++) {
   printf("%s\n", argv[i]);
}

(Edit: Thx for your comments, my C is really a bit rusty.)

pzaenger
  • 7,620
  • 2
  • 31
  • 39