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
your
main()has wrong signature. it's notint main(int argc, char* argv)it's
int main(int argc, char **argv)or equivalently
int main(int argc, char *argv[])you trying print
char"%s"specifier,printf()function tries read string , interpretscharvalue address because it's expectingcharpointer, leads undefined behavior1 , hence problem.
1please read link posted @souravghosh answer advice.
Comments
Post a Comment