[SOLVED] add quotes to both side of a char variable, how to? C
by BW-userx from LinuxQuestions.org on (#4T16R)
I am giving up on trying to figure out (for now anyways).
How to add a double quote to each side of an already existing variable into another or same named variable to use it later on in a different program.
this program is my "testing program" to figure out what I need before moving it all into the other one.
Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char fixcolors[145][21]={
"Alice Blue",
"Antique White",
"Aqua",
"Aquamarine",
"Azure",
"Beige",
"Bisque",
"Black",
"Blanched Almond",
"Blue",
"Blue Violet",
"Brown",
"Burlywood",
"Cadet Blue",
"Chartreuse",
"Chocolate",
"Coral",
"Cornflower Blue",
"Cornsilk",
"Crimson",
"Cyan",
"Dark Blue",
"Dark Cyan",
"Dark Goldenrod",
"Dark Gray",
"Dark Green",
"Dark Khaki",
"Dark Magenta",
"Dark Olive Green",
"Dark Orange",
"Dark Orchid",
"Dark Red",
"Dark Salmon",
"Dark Sea Green",
"Dark Slate Blue",
"Dark Slate Gray",
"Dark Turquoise",
"Dark Violet",
"Deep Pink",
"Deep Sky Blue",
"Dim Gray",
"Dodger Blue",
"Firebrick",
"Floral White",
"Forest Green",
"Fuchsia",
"Gainsboro",
"Ghost White",
"Gold",
"Goldenrod",
"Gray",
"Web Gray",
"Green",
"Web Green",
"Green Yellow",
"Honeydew",
"Hot Pink",
"Indian Red",
"Indigo",
"Ivory",
"Khaki",
"Lavender",
"Lavender Blush",
"Lawn Green",
"Lemon Chiffon",
"Light Blue",
"Light Coral",
"Light Cyan",
"Light Goldenrod",
"Light Gray",
"Light Green",
"Light Pink",
"Light Salmon",
"Light Sea Green",
"Light Sky Blue",
"Light Slate Gray",
"Light Steel Blue",
"Light Yellow",
"Lime",
"Lime Green",
"Linen",
"Magenta",
"Maroon",
"Web Maroon",
"Medium Aquamarine",
"Medium Blue",
"Medium Orchid",
"Medium Purple",
"Medium Sea Green",
"Medium Slate Blue",
"Medium Spring Green",
"Medium Turquoise",
"Medium Violet Red",
"Midnight Blue",
"Mint Cream",
"Misty Rose",
"Moccasin",
"Navajo White",
"Navy Blue",
"Old Lace",
"Olive",
"Olive Drab",
"Orange",
"Orange Red",
"Orchid",
"Pale Goldenrod",
"Pale Green",
"Pale Turquoise",
"Pale Violet Red",
"Papaya Whip",
"Peach Puff",
"Peru",
"Pink",
"Plum",
"Powder Blue",
"Purple",
"Web Purple",
"Rebecca Purple",
"Red",
"Rosy Brown",
"Royal Blue",
"Saddle Brown",
"Salmon",
"Sandy Brown",
"Sea Green",
"Seashell",
"Sienna",
"Silver",
"Sky Blue",
"Slate Blue",
"Slate Gray",
"Snow",
"Spring Green",
"Steel Blue",
"Tan",
"Teal",
"Thistle",
"Tomato",
"Turquoise",
"Violet",
"Wheat",
"White",
"White Smoke",
"Yellow",
"Yellow Green"
};
#define ARRAY_SIZE( array ) ( sizeof( array ) / sizeof( array[0] ) )
char * randomColors(void)
{
int upper = ARRAY_SIZE(fixcolors);
int i = 0, num = 0, lower = 1, count = 1;
for (i = 0; i < count; i++) {
num = (rand() %
(upper - lower + 1)) + lower;
}
return fixcolors[ num ];
}
int main(void)
{
char *color = NULL;
printf("Number of rows: %d\n", ARRAY_SIZE(fixcolors));
printf("Number of columns: %d\n", ARRAY_SIZE(fixcolors[0]));
/*
for (int i = 0; i<ARRAY_SIZE(fixcolors);i++)
{
printf("%s\n",fixcolors[i]);
}
for (int i=0;i<10;i++)
printf("%s\n", printRandoms () );
*/
color = strdup ( randomColors() );
strcat(color, "\"");
printf("%s\n", color);
return 0;
}strcat is right side, how do I get a quote on the left side?
I seen a strrev that is suppose to be in string.h but not in this one.
https://www.programmingsimplified.co...reverse-string
Code:blue
//to be
"blue"in the variable itself so printf gets me
Code:printf("%s\n",color);
"blue"


How to add a double quote to each side of an already existing variable into another or same named variable to use it later on in a different program.
this program is my "testing program" to figure out what I need before moving it all into the other one.
Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char fixcolors[145][21]={
"Alice Blue",
"Antique White",
"Aqua",
"Aquamarine",
"Azure",
"Beige",
"Bisque",
"Black",
"Blanched Almond",
"Blue",
"Blue Violet",
"Brown",
"Burlywood",
"Cadet Blue",
"Chartreuse",
"Chocolate",
"Coral",
"Cornflower Blue",
"Cornsilk",
"Crimson",
"Cyan",
"Dark Blue",
"Dark Cyan",
"Dark Goldenrod",
"Dark Gray",
"Dark Green",
"Dark Khaki",
"Dark Magenta",
"Dark Olive Green",
"Dark Orange",
"Dark Orchid",
"Dark Red",
"Dark Salmon",
"Dark Sea Green",
"Dark Slate Blue",
"Dark Slate Gray",
"Dark Turquoise",
"Dark Violet",
"Deep Pink",
"Deep Sky Blue",
"Dim Gray",
"Dodger Blue",
"Firebrick",
"Floral White",
"Forest Green",
"Fuchsia",
"Gainsboro",
"Ghost White",
"Gold",
"Goldenrod",
"Gray",
"Web Gray",
"Green",
"Web Green",
"Green Yellow",
"Honeydew",
"Hot Pink",
"Indian Red",
"Indigo",
"Ivory",
"Khaki",
"Lavender",
"Lavender Blush",
"Lawn Green",
"Lemon Chiffon",
"Light Blue",
"Light Coral",
"Light Cyan",
"Light Goldenrod",
"Light Gray",
"Light Green",
"Light Pink",
"Light Salmon",
"Light Sea Green",
"Light Sky Blue",
"Light Slate Gray",
"Light Steel Blue",
"Light Yellow",
"Lime",
"Lime Green",
"Linen",
"Magenta",
"Maroon",
"Web Maroon",
"Medium Aquamarine",
"Medium Blue",
"Medium Orchid",
"Medium Purple",
"Medium Sea Green",
"Medium Slate Blue",
"Medium Spring Green",
"Medium Turquoise",
"Medium Violet Red",
"Midnight Blue",
"Mint Cream",
"Misty Rose",
"Moccasin",
"Navajo White",
"Navy Blue",
"Old Lace",
"Olive",
"Olive Drab",
"Orange",
"Orange Red",
"Orchid",
"Pale Goldenrod",
"Pale Green",
"Pale Turquoise",
"Pale Violet Red",
"Papaya Whip",
"Peach Puff",
"Peru",
"Pink",
"Plum",
"Powder Blue",
"Purple",
"Web Purple",
"Rebecca Purple",
"Red",
"Rosy Brown",
"Royal Blue",
"Saddle Brown",
"Salmon",
"Sandy Brown",
"Sea Green",
"Seashell",
"Sienna",
"Silver",
"Sky Blue",
"Slate Blue",
"Slate Gray",
"Snow",
"Spring Green",
"Steel Blue",
"Tan",
"Teal",
"Thistle",
"Tomato",
"Turquoise",
"Violet",
"Wheat",
"White",
"White Smoke",
"Yellow",
"Yellow Green"
};
#define ARRAY_SIZE( array ) ( sizeof( array ) / sizeof( array[0] ) )
char * randomColors(void)
{
int upper = ARRAY_SIZE(fixcolors);
int i = 0, num = 0, lower = 1, count = 1;
for (i = 0; i < count; i++) {
num = (rand() %
(upper - lower + 1)) + lower;
}
return fixcolors[ num ];
}
int main(void)
{
char *color = NULL;
printf("Number of rows: %d\n", ARRAY_SIZE(fixcolors));
printf("Number of columns: %d\n", ARRAY_SIZE(fixcolors[0]));
/*
for (int i = 0; i<ARRAY_SIZE(fixcolors);i++)
{
printf("%s\n",fixcolors[i]);
}
for (int i=0;i<10;i++)
printf("%s\n", printRandoms () );
*/
color = strdup ( randomColors() );
strcat(color, "\"");
printf("%s\n", color);
return 0;
}strcat is right side, how do I get a quote on the left side?
I seen a strrev that is suppose to be in string.h but not in this one.
https://www.programmingsimplified.co...reverse-string
Code:blue
//to be
"blue"in the variable itself so printf gets me
Code:printf("%s\n",color);
"blue"