Why 'segmentation fault' occurs in the following C code -


$hoho   b  abcd  $hoho | lala  segmentation fault 

lala.c -->

#include<stdio.h> int main(int argc, char* argv){  printf("%s\n", argv[1]);  ... } 

then, how can use std_input a, b , abcd

  1. your main() has wrong signature. it's not

    int main(int argc, char* argv) 

    it's

    int main(int argc, char **argv) 

    or equivalently

    int main(int argc, char *argv[]) 
  2. you trying print char "%s" specifier, printf() function tries read string , interprets char value address because it's expecting char pointer, leads undefined behavior1 , hence problem.


1please read link posted @souravghosh answer advice.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -