Question

1. Given the string variables pres, first, and last as defined in Example 9.2 provided on...

1. Given the string variables pres, first, and last as defined in Example 9.2 provided on page 459 of your textbook, Problem Solving and Program Design in C, show what would be displayed by this code fragment. (If you do not know, you can always place this code into the proper C coding structure and compile and execute.) Make certain your call includes <stdio.h> and <string.h> and declare your variables if you are going to compile. (Hint:Refer to the text below the first paragraph on p.459 of your textbook for assistance.)

strncpy(first, pres, 2);

first[2] = '\0';

printf("%s", first);

printf("\n");

printf(" %s", strcpy(last, &pres[7]));

strncpy(first, &pres[7], 2);

first[2] = '\0';

strncpy(last, &pres[14], 2);

last[2] = '\0';

printf("\n");

printf(" %s%s\n\n", first, last);

2. Refer to these declarations when determining the effect of the statements in the following questions (record your answers for the results of each bullet):

char s5[5], s10[10], s20[20];

char aday[7] = "Sunday";

char another[9] = "Saturday";

i. strncpy(s5, another, 4);

s5[4] = '\0';

ii. strcpy(s10, &aday[3]);

iii. strlen(another)

iv. strcpy(s20, aday); strcat(s20, another);

v. Which one of the following would call somefun only if the string values of character arrays a and b were equal?

a. if (strcmp(a, b))

somefun();

b. if (strcmp(a, b) == 0)

somefun();

c. if (a == b)

somefun();

d. if (a[] == b[])

somefun();

vi. What does this program fragment display?

char x[80] = "gorilla";

char y[80] = "giraffe";

strcpy(x, y);

printf("%s %s\n", x, y);

a. What does this program fragment display?

char x[80] = "gorilla";

char y[80] = "giraffe";

strcat(x, y);

printf("%s %s\n", x, y);

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
1. Given the string variables pres, first, and last as defined in Example 9.2 provided on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • -I need to write a program in C to store a list of names (the last...

    -I need to write a program in C to store a list of names (the last name first) and age in parallel arrays , and then later to sort them into alphabetical order, keeping the age with the correct names. - Could you please fix this program for me! #include <stdio.h> #include <stdlib.h> #include <string.h> void data_sort(char name[100],int age[100],int size){     int i = 0;     while (i < size){         int j = i+1;         while (j < size){...

  • Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(...

    Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(char *s) {    /* this is here so code compiles */ return 0; } /* array version */ /* concantenate t to the end of s; s must be big enough */ void str_cat(char s[], char t[]) {    int i, j;    i = j = 0;    while (s[i] != '\0')    /* find end of s */        i++;    while ((s[i++] = t[j++]) != '\0') /* copy t */        ;...

  • Identify and list all the User defined Functions to be used in the system #include <stdio.h>...

    Identify and list all the User defined Functions to be used in the system #include <stdio.h> ///for input output functions like printf, scanf #include <stdlib.h> #include <conio.h> #include <windows.h> ///for windows related functions (not important) #include <string.h> ///string operations /** List of Global Variable */ COORD coord = {0,0}; /// top-left corner of window /** function : gotoxy @param input: x and y coordinates @param output: moves the cursor in specified position of console */ void gotoxy(int x,int y) {...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Please help in answering these questions dealing with this one prompt: 1 Which line is first...

    Please help in answering these questions dealing with this one prompt: 1 Which line is first line of the date structure prototype (blueprint)? 30 21 7 59 2 Which line is date structure declared inside another structure prototype? 21 32 36 60 3 What is the structure tag which has date as a data member? date him student her 4 Which line is a student structure instance declared (created)? 17 30 25 55 5 Which line is a student structure...

  • #include <stdio.h> #include <stdlib.h> #include <string.h> struct game_piece { ...

    #include <stdio.h> #include <stdlib.h> #include <string.h> struct game_piece { }; struct game_board { }; void game_piece_init_default(struct game_piece* piece) { } void game_piece_init(struct game_piece* piece, char* new_label) { } char* game_piece_get_label(struct game_piece* piece) { return ""; } char* game_piece_to_string(struct game_piece* piece) { return ""; } void game_board_init(struct game_board* game_board, int rows, int cols) { } int game_board_is_space_valid(struct game_board* game_board, int row, int col) { return 0; } int game_board_add_piece(struct game_board* game_board, struct game_piece* piece, int row, int col) { return 0;...

  • In this activity, you will complete the RSS Client that connects to a UNL RSS feed,...

    In this activity, you will complete the RSS Client that connects to a UNL RSS feed, processes the XML data and outputs the results to the standard output. Most of the client has been completed for you. You just Lab Handout: Structures 4 need to complete the design and implementation of a C structure that models the essential parts of an RSS item. Your structure will need to support an RSS item’s title, link, description, and publication date. As a...

  • Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will...

    Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will call our version MyString. This object is designed to make working with sequences of characters a little more convenient and less error-prone than handling raw c-strings, (although it will be implemented as a c-string behind the scenes). The MyString class will handle constructing strings, reading/printing, and accessing characters. In addition, the MyString object will have the ability to make a full deep-copy of itself...

  • #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate...

    #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT