Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.1 Specification Write an ANSI-C program that reads from standard input a word (string with no spaces) followed by a character, and then outputs the

image text in transcribed

image text in transcribed

4.1 Specification Write an ANSI-C program that reads from standard input a word (string with no spaces) followed by a character, and then outputs the word, the number of characters in the word, and the index of the character in the word. 4.2 Useful information Note that C has no string type, so when you declare literal "hello", the internal representation is an array of characters, terminated by a special null character 10', which is added for you automatically. So char helloArrll"hello" will give helloArr a representation of 'h | ' e ' | ' I ' | ' I ' | ' o '|0'1 , which has size 6 bytes, not 5 As shown earlier, one way to read a word from the standard input is to use scanf, which is passed as argument a "string" variable, when using scanf ("%s", arrayName) , the trailing character O is added for you 4.3 Implementation . name your program lab2C.c .define a char array to hold the input word. Assume each input word contains no more than 20 characters (so what is the minimum capacity the array should be decleared to have?). use scanf define a functionint length (char word[]) which returns the number of characters in word (excluding the trailing character \O'). This function is similar to strlen (s) Clibrary function shown earlier, and s.length ) method in Java. ("%s % c", ) to read the word and char. . define a function int indexof (char wordI, char c) which returns the index (position of the first occurrence) of c in word. Return-1 if c does not occur in word. This function is similar to s.indexof ()method in Java . do not use any existing function from the string library. keep on reading until a word "quit" is read in, followed by any character. Hint: You can compare the word against the pre-defined terminating token quit by characters. Define a function int isQuit (char wordI]) which checks if word is "quit". Later we will learn how to compare two "strings" using library functions). 4.4 Sample Inputs/Outputs: (output is on a single line) red 308 gcc -Wall lab2C.c-o lab2c red 309 % lab2c Enter a word and a character separated by blank: hello x Input word is "hello". Contains 5 characters. Index of 'x' in it is -1 Enter a word and a character separated by blank: hello 1 Input word is "hello". Contains 5 characters. Index of 'l' in it is 2 Enter a word and a character separated by blank: beautifulWord u Input word is "beautifulWord". Contains 13 characters. Index of 'u' in it is3 Enter a word and a character separated by blank: quit x red 310 %

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

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

Students also viewed these Databases questions

Question

5. How would you describe your typical day at work?

Answered: 1 week ago

Question

7. What qualities do you see as necessary for your line of work?

Answered: 1 week ago