Trouble \0 null terminating a string (C) -


I think there is some problem with terminating my string with \ 0. I'm not sure that this is a problem, so I decided to make a post.

First of all, I declared my wire in this form:

  char * input2 [5];   

Later in the program, I added this line of code to become the remaining unused slots to be \ 0 , all of them changed to become a tap terminator Gave. Can be done with a loop, but yes.

  while (c! = 4) {input2 [c] = '\ 0'; C ++; }   

When in debug mode, I see that the empty slot now has 0x0, not \ 0 is this the same thing? The second string where I declared it

  four input [15] = "";   

then shows when happening in debug mode.

My problem is that I'm getting a partition error ( Debian VM ). My linux 12.04 though). My guess is that because the string is not really finished, the compiler does not know when it closes and continues to try to reach the memory in the array, when it is clearly out of bounds already .

Edit: I will try to answer all other questions soon, but when I change my string announcement for the second suggestion, my program crashes there Have a strtok () function, used to cut my fgets input into the wire and then put them in my input2 array.

Then,

  input 1 [0] = 'L' input 1 [1] = 's' input1 [2] = '\ n' Input 2 [0 ] = "Ls"   

This is an simulation program with Prison and execvp. I will post more codes shortly.

About suggestions:

four * Input 2 [5]; This is a completely legal declaration, but it defines input 2 as an array of pointers. To include the string, it needs to be an array of four.

I will try that change again. I tried earlier, but I remember giving me another run-time error (seg mistake?). I think that because of this I implemented my strtok () function though. I'll check it again thanks!

Edit 2: I have added a response below to update my progress. Thanks for all the help!

You should see the code like this:

  Four input 2 [ 5]; For (int c = 0; c <; 4; c ++) {input2 [c] = '\ 0'; }   

0x0 and \ 0 different representations of equal value 0;

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -