Question: For the C code below how can I insert a string value into each index? I tried using the strcpy() function to store a string

For the C code below how can I insert a string value into each index? I tried using the strcpy() function to store a string value but it keeps on giving me a segmentation error. Can someone fix my code?

#include #include const int row = 10; const int col = 2; char *a[][2] = { {"",""}, {"",""}, {"Jim","Bob"}, {"Mike","OS"}, {"",""}, {"",""}, {"Jane Doe"," Mark Kim"}, {"Amber",""}, {"",""}, {"","CSE-460"} }; int main() { strcpy(a[0][0], "hello!"); strcpy(a[3][1], ""); for(int i = 0; i < row; i++) { for(int j = 0; j < col; j++) { printf(" [%d][%d] -> %s ", i , j, a[i][j]); if(j == 1) printf(" "); } }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!