Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Why is stakeholder engagement important?

Answered: 1 week ago