Question

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 the character after the last character of the string itself will be a 0,-also known as the NULL c scanf wil fill the array with the characters typed in at the keyboard AND it will put the \0 at the end for us. So if the user types Alfred, the array will look like: name) ; with the char array that we declared above haracter. If we do this scanf ( %s, This means that we always have to declare the array to be one larger than the maximum number of we dont know whats in those spaces and we dont care.) a lot of characters into it, lets make its size 100. ters we are anticipating will be entered. (Notice in the above there are spaces left after the 10- Begin thislab by starting a new file and declaring a string variable (char array). Since we may want to put Now, using scanf and %s as you saw in the paragraph above, ask for and read in the users first nane. Notice that the scanf does not require the use of the & in this case. This is because the name of an array always holds the address of the first element, giving the scanf the power to write directly into the array Then print if out using printf and the %s format placeholder. Compile and run this. It should run like this: Enter your name: Alfred Hello Alfred! When we pass these arrays to functions we do not need to pass the number of elements in the array since we can always find the end of the valid elements by searching for the 10. (namei)10) For the next step in the lab, write and call a function int getLength (char str[l) which returns the number of characters in your name. When you compile and run this it should tell you Enter your name: Alfred Hello Alfred! Your name has 6 letters. (Obviously it should be your own name.) Now what happens when you try typing your first and last name? Run the program this way and find out. were you surprised that you only see your first name? The problem is that using scanf and %s always stops reading in at the first space. But you can have strings with spaces in them. After all, a space is a perfectly valid character. The way to read to a string with spaces is with gets like this: gets (name) This function stops at the newline character which is the Enter key. It does not store the enter key. Change the scanf in your program to a gets (name): OVER)

Write in C

Write in C
0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • C programming 1 String Merging Write a program that reads two strings s1 and s2 from...

    C programming 1 String Merging Write a program that reads two strings s1 and s2 from the keyboard and merges them to a string s3. Strings s1 and s2 are statically allocated whereas s3 is dynamically allocated to fit exactly s1 and s2. The two original strings are no longer than 100 characters long. Use the following function to merge the two strings. char *stringMerge(char s1[], char s2 []); Example: Enter the first string: Hello world Enter the first string:...

  • This program should be run on Visual Studio. Please use printf and scanf as input and output. Tha...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs You will write 2 functions which resemble functions in the cstring library. But they will be your own versions 1. int cstrcat(char dstDchar src) which concatenates the char array srcl to char array dstD, and returns the...

  • 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...

  • 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...

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • write program in C language. To get more practice working with files, you will write several...

    write program in C language. To get more practice working with files, you will write several functions that involve operations on files. In particular, implement the following functions 1. Write a function that, given a file path/name as a string opens the file and returns its entire contents as a single string. Any endline characters should be preserved char *getFileContents (const char filePath); 2. Write a function that, given a file path/name as a string opens the file and returns...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. 1. write the code using function 2. Please try to implement a function after the main function and provide prototype before main function. Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...

  • In this programming assignment we will review string and character manipulations. You will be developing a...

    In this programming assignment we will review string and character manipulations. You will be developing a Java program that will prompt users for person’s last name, year of birth, and employee number in a predefined specific format. You will then parse the input string and print it in separate lines along with validations. The input format will be of the form :,< employee number > You will need to separate three segments in order to print it as: Last name...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

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
Active Questions
ADVERTISEMENT