Skip to main content
Formatting
Source Link
John Burger
  • 1.9k
  • 1
  • 14
  • 24

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later espData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x];            // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {        // If it's NOT a colon
            *output++ = espData[x][i];    // Copy character 'up'
        } // if
                                          // If it WAS a colon, then
                                          // output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later espData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x]; // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {     // If it's NOT a colon
            *output++ = espData[x][i]; // Copy character 'up'
        } // if
        // If it WAS a colon, then output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later espData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x];            // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {        // If it's NOT a colon
            *output++ = espData[x][i];    // Copy character 'up'
        } // if
                                          // If it WAS a colon, then
                                          // output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for
Typo
Source Link
John Burger
  • 1.9k
  • 1
  • 14
  • 24

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later expData[x]espData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x]; // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {     // If it's NOT a colon
            *output++ = espData[x][i]; // Copy character 'up'
        } // if
        // If it WAS a colon, then output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later expData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x]; // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {     // If it's NOT a colon
            *output++ = espData[x][i]; // Copy character 'up'
        } // if
        // If it WAS a colon, then output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later espData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x]; // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {     // If it's NOT a colon
            *output++ = espData[x][i]; // Copy character 'up'
        } // if
        // If it WAS a colon, then output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for
Added code for what is wanted
Source Link
John Burger
  • 1.9k
  • 1
  • 14
  • 24

You've assumed that a char * is some kind of string object, since you've got the following line fof code: output += expData[x][i];espData[x][i];, and then later expData[x] = output;

It quite simply doesn't work like that. At best you can point output inside expData[x]espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x]; // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {     // If it's NOT a colon
            *output++ = espData[x][i]; // Copy character 'up'
        } // if
        // If it WAS a colon, then output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for

You've assumed that a char * is some kind of string object, since you've got the following line f code: output += expData[x][i];, and then later expData[x] = output;

It quite simply doesn't work like that. At best you can point output inside expData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

You've assumed that a char * is some kind of string object, since you've got the following line of code: output += espData[x][i];, and then later expData[x] = output;

It quite simply doesn't work like that. At best you can point output inside espData[x] and then do some other logic: but your attempt to "accumulate" the correct characters is incorrect.

Please consider the following code instead:

char* espData[15];

for(int x = 0; x < index-1; x++){
    size_t nullTerm = strlen(espData[x]); // Get current length
    char* output = espData[x]; // Start of string
    for (size_t i = 0; i < nullTerm; ++i){
        if(espData[x][i] != ':') {     // If it's NOT a colon
            *output++ = espData[x][i]; // Copy character 'up'
        } // if
        // If it WAS a colon, then output does NOT get incremented
    } // for
    *output = '\0'; // End string off with NUL
    Serial.println(espData[x]);
} // for
Source Link
John Burger
  • 1.9k
  • 1
  • 14
  • 24
Loading