Two variables sharing memory?
I was just playing around with some C code, trying to get the hang of it, and ended up with this:
Code:
#include <string.h> Code:
$ gcc blahfan.c -o temp -std=c99 |
port_str and second are pointing to the same place in memory. I'll bet that the port_str[c] = "\0" isn't executing at all, and that the length of that array is 0. I'll go see...
|
char first[strlen(argv[1]+1)];
First of all, the length should be known at compile time to be able to determine what the length of first should be. Otherwise you need to have first and second be dynamically allocated, which will probably mean that they should be pointers to an array of char. Second, I think you wanted [ strlen(argv[1]) + 1 ] You are checking the length of the string starting with the second character, rather then adding one to the string length. |
All times are GMT -5. The time now is 10:36 PM. |