Change string elements according to user input

hello, i have here is a simple program that has initial string values. the user must first pick a location of the color and after that, change it to whatever he inputs then displays the new values

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

int main()
{  
    char* col[1][5]={"red","blue","white","gold","silver"};
    
    int x,y,ch;
    for (x = 0; x < 1; x++)
    {
    for ( y = 0; y < 5; y++)
    {
    printf("%20s\n",col[x][y]);                                   
    }}
    printf("location to change:\n");
    printf("Col:\n");
    scanf("%d",&x);
    printf("Row:\n");
    scanf("%d",&y);
                                   
    printf("Please enter color:\n");
                                   
    scanf("%s",&col[x][y]);
    for (x = 0; x < 1; x++)
    {
    for ( y = 0; y < 5; y++)
    {
    printf("%20s\n",col[x][y]);                                   
    }}
system("pause");
return(0);
getch();
}

but after i input the color, the program closes what do i do? thanks!

You are probably accessing an undefined bit of memory. You have a few problems with your code. Firstly, why don't you just use a one dimensional array? Apart from that, you have defined it as a three dimensional array (notice the pointer in the declaration), which means that your program is overwriting memory pointed to randomly by that pointer.
Last edited on
thanks, i changed it to a 1d array but if i removed the pointer, i kept on getting conversion errors
Topic archived. No new replies allowed.