You are here:

C++/character string

Advertisement


Question
Hi,

How are you?
I have a 2D character string that I declare as:

char mytable[3][4]={"how","are","you"};

Why cannot I print out individual words from that?
I want the program to show the first word but

printf("%s", mytable[1]);//won't work
printf("%s", mytable[1][1]);//won't work

How do you print out individual words?
Thanks


Answer
hi Eric

There is really no problem in your code. the defect may be with your compiler.

Please compile and run this code and try out it works or not.

char str[5][5];
int i;
for(i=0;i<10;i++)
gets(str[i]);

for(i=0;i<5;i++)
printf("%s",str[i]);

This just takes 5 string and prints them. Do lemme know in case of problems.

regards
Joydeep Bhattacharya
http;//www.scodz.com

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

TSR, Socket and Very Complex Mathematical Problem

Experience

Worked on many OOP projects with design patterns

Organizations
http://www.scodz.com

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Awards and Honors
Being a proud owner of a website of programming called http://www.scodz.com

Past/Present Clients
http://www.funforu.com http://www.dhoondho.com http://analysingc.50webs.com

©2016 About.com. All rights reserved.