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

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -