1
Exit status -1
Yuvikiit (0)

This is my code and I am not getting why is it showing exit status -1.
Please answer:)
#include<stdio.h>
#include<string.h>
int main()
{
int i;
char c,d,e;
scanf("%s",c); //to take in the 1st string
scanf("%c",&d);//after string the newline char needs to get in the buffer
scanf("%s",e); //to take in another string
printf("%s\n%s",c,e); //to print both the strings
return 0;
}

You are viewing a single comment. View All
Answered by mwilki7 (117) [earned 5 cycles]
View Answer
1
Yuvikiit (0)

@mwilki7 Sankyu(Thanks) Sir for the reply, just let me know one more thing
Like why this works for a single string.
and how does it work:
I thought in the manner that being a character pointer
the pointer would store 1 character as I am entering and then will move to next byte for latter entry and as soon as I press enter it puts a '\0' at the end and completes the string,

And I also don't know like why this should be a problem even
is it because that the pointer has some garbage address stored in it and it is not a good programming practice to store our string at some garbage place though, the memory chunks might be continuous (as the char pointer
does that bit by default.)

//Please answer:)
#include<stdio.h>
#include<string.h>
int main()
{
  int i;
  char *c,d,*e;
  scanf("%s",c); //to take in the 1st string  
  //scanf("%c",&d);//after string the newline char needs to get in the buffer
  //scanf("%s",e); //to take in another string
  printf("%s\n",c); //to print both the strings
   return 0;
}

and
let me know is it some compiler dependant thing because I tried the same thing in Codeblocks and it didn't work.

Thanks once again for the help.