简体   繁体   中英

Removing First and Last Character from string array

Hello im trying to find a way to remove the first and last character of an array of strings.

My data insight the array is something like this:

"Time1":

"3.0"

etc.

Im trying specifically to remove the double quotes and the char: What should i use?

char item[100]; 
   char  LastArray[1000];
   while (NewMixedArray[i] != NULL)
   {
    sscanf (NewMixedArray[i],"\"%99[^\"]", item);
    LastArray[i]=item;
    printf("%d %s\n",i,LastArray[i]);
    i++;
   }

   i=0;
   while (  LastArray[i] != NULL)
   {
    printf("DONE: %d %s\n",i,LastArray[i]);
    i++;
   }

On the second printf im getting only the last value.

https://i.imgur.com/H2OFz1Q.png

I found my problem i used the command

LastArray[i] = strdup(item); Because my LastArray was an array of pointers.

#include <stdio.h>
#include <string.h>

int main() {
    char string[1000], result[1000];
    strcpy(string, "\"Time1\":");

    printf("\nInitial String : %s", string);
    int i;
    int c = 0;
    do {
        if (string[i] != '\"' & string[i] != ':') {
            result[c] = string[i];
            c++;
        }
        i++;
    } while (string[i] != '\0');

    printf("\nResult : %s\n", result);
    return 0;
}

Result

$ ./ss

Initial String : "Time1":
Result : Time1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM