Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Linux using by C++ 1) Try below and explain why we have an error. char *y; y=hello; // this is ok strcpy(y, hello); //

In Linux using by C++

1) Try below and explain why we have an error.

char *y;

y="hello"; // this is ok

strcpy(y, "hello"); // this is an error

2) Define a character pointer array and store/display strings as below.

char * x[10];

x[0]="hi"; x[1]="bye"; x[2]="hello";

printf("%s %s %s ", x[0],x[1],x[2]);

3) Read the same sentence with gets() and fgets() and explain the difference.

char x[100];

printf("enter a sentence ");

gets(x);

int slen=strlen(x);

for(i=0;i

printf("%x ", x[i]);

}

printf(" enter the same sentence ");

fgets(x, 100, stdin);

slen=strlen(x);

for(i=0;i

printf("%x ", x[i]);

}

4) Use strtok to extract words from a sentence and store them in an array. Display the number of words as below. Use as many functions as possible to split your program into small pieces.

algorithm:

read a line

tokenize

display tokens

Enter a sentence

aa bcd e e ff aa bcd bcd hijk lmn al bcd

You entered aa bcd e e ff aa bcd bcd hijk lmn al bcd

There were 12 words:

aa

bcd

e

e

ff

aa

bcd

bcd

hijk

lmn

al

bcd

The original sentence was: aa bcd e e ff aa bcd bcd hijk lmn al bcd

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

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 Tsukuba Japan April 2010 Proceedings Part 1 Lncs 5981

Authors: Hiroyuki Kitagawa ,Yoshiharu Ishikawa ,Wenjie Li ,Chiemi Watanabe

2010th Edition

3642120253, 978-3642120251

More Books

Students also viewed these Databases questions