Question

Hi everyone, I have a problem about C programming.

Background Material:

well consider only strings that are made using character codes from the ASCII character set, which is listed as a table in Figure 6. ASCII is reasonably good for text in English, but is obviously not at all adequate for text in most other human languages. Its possible in C to manage strings that could contain any characters from any written language, but thats an advanced topic Most of Figure 6 is self-explanatory, but there are a few things about it that could use a little extra explanation . The codes corresponding to decimal number from 0 up to and including 31, and also 127, are called control characters. Most of them have very little use in modern computing, but some of them are very important, such as 0 the null character, 9-the tab character, 10-the newline character, and a few others. The table shows how to represent character 92, the backslash character, as a C character constant. Here is how to write a single quote as a character constant: On a somewhat related note, here is how to insert double quotes into a string constant: Id like to say Hello!\ to my friends!

The figure 6 is as below:

The task:

Download the file 55.c. Study the C code, then build an executable and run it to see what the output is. Modify the program so that the output is The string in buffer is "In C the value of 12 + 34 / 5 is 18." Do this by looking up decimal values for ASCII codes in Figure 6 and typing them into the .c file as necessary—in this exercise you’re not allowed to add character constants or string constants to the C code.

The answer:

The printout of complete code of 55.c

Below is the file 55.c:

#include <stdio.h>

int main(void)
{
  char buffer[80];   // enough space for a string of length <= 79

  // THIS IS A GOOD WAY TO LEARN SOMETHING ABOUT C STRINGS, BUT IT'S
  // NOT A GOOD EXAMPLE OF READABLE OR PRACTICAL CODE! 

  // Put characters into the string using ASCII codes.
  buffer[0] = 84;
  buffer[1] = 104;
  buffer[2] = 105;
  buffer[3] = 115;
  buffer[4] = 32;
  buffer[5] = 105;
  buffer[6] = 115;
  buffer[7] = 32;
  buffer[8] = 69;
  buffer[9] = 78;
  buffer[10] = 67;
  buffer[11] = 77;
  buffer[12] = 32;
  buffer[13] = 51;
  buffer[14] = 51;
  buffer[15] = 53;
  buffer[16] = 33;
  buffer[17] = 0;

  // Put the end-of-string character at the end of the string.
  buffer[17] = 0;

  printf("The string in buffer is \"%s\"\n", buffer);
  return 0;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

Output is: The string in buffer is "This is ENCM 335!"

Modified program:

#include <stdio.h>

int main(void)

{

char buffer[80]; // enough space for a string of length <= 79

// THIS IS A GOOD WAY TO LEARN SOMETHING ABOUT C STRINGS, BUT IT'S

// NOT A GOOD EXAMPLE OF READABLE OR PRACTICAL CODE!

// Put characters into the string using ASCII codes.

buffer[0] = 73;

buffer[1] = 110;

buffer[2] = 32;

buffer[3] = 67;

buffer[4] = 32;

buffer[5] = 116;

buffer[6] = 104;

buffer[7] = 101;

buffer[8] = 32;

buffer[9] = 118;

buffer[10] = 97;

buffer[11] = 108;

buffer[12] = 117;

buffer[13] = 101;

buffer[14] = 32;

buffer[15] = 111;

buffer[16] = 102;

buffer[17] = 32;

buffer[18] = 49;

buffer[19] = 50;

buffer[20] = 32;

buffer[21] = 43;

buffer[22] = 32;

buffer[23] = 51;

buffer[24] = 52;

buffer[25] = 32;

buffer[26] = 47;

buffer[27] = 32;

buffer[28] = 53;

buffer[29] = 32;

buffer[30] = 105;

buffer[31] = 115;

buffer[32] = 32;

buffer[33] = 49;

buffer[34] = 56;

buffer[35] = 46;

// Put the end-of-string character at the end of the string.

buffer[36] = 0;

printf("The string in buffer is \"%s\"\n", buffer);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Hi everyone, I have a problem about C programming. Background Material: The figure 6 is as...
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
  • Hi everyone, I have a C programming problem, answers are better with explanations. Background Materials: The...

    Hi everyone, I have a C programming problem, answers are better with explanations. Background Materials: The Task: The Answer: The completed C code. Below is the file charIO4C.c: #include <stdio.h> #include <ctype.h> #define QUIT_LETTER 'q' int main(void) { int c, line_length; // Each pass through the outer loop reads a line of input. while (1) { printf("\nEnter a line of text. (To quit, start the line with %c.)\n", QUIT_LETTER); c = fgetc(stdin); if (c == EOF || c == QUIT_LETTER)...

  • Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for...

    Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for push_back() function as below: void push_back(string str) { // increase vector size by one // initialize the new element with str } In addition, the standard library vector doesn't provide push_front(). Implement push_front() for your vector. Test your code with the main function below. int main() {    vector v1(3);    cout<<"v1: ";    v1.print(); // this should display -, -, -    for...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • In C please : The tasks in this exam review exercise are structured in levels. You...

    In C please : The tasks in this exam review exercise are structured in levels. You can see the point distribution for the levels at the end. It is strongly recommended that you ensure you have passed all test cases of lower levels before moving up to a higher level. For example, ensure you have completed all Level 0 and 1 tasks before even looking at Level 2 Tasks. MESSAGE ENCODER LEVEL 0: (test cases - 50 points) Start by...

  • C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the...

    C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the Facility.cpp file and the other files are included in case they're needed for understanding. I was able to complete the mayday.cpp file but am stuck on Facility. The following link contains a tar file with the files provided by the professor. Thank you so much in advanced! http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/ Closer.h: #ifndef CLOSER_H #define CLOSER_H #include <string> #include "gcdistance.h" struct Closer { const double latitude, longitude;...

  • I need help finding what is wrong with this code, it is for a CS course...

    I need help finding what is wrong with this code, it is for a CS course I am taking which codes in C (I am using XCode on Mac to code). This is the assignment: "Write a program that performs character processing on 10 characters read in from a file, and writes the results to output files. The program should read from “input.dat”. The program should write the ASCII values of the characters to “output_ascii.dat”. The program should print statistics...

  • Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description:...

    Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...

  • C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪...

    C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪ Writing a while loop ▪ Write functions and calling functions Text Processing [50 points] We would like to demonstrate our ability to control strings and use methods. There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

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