Question

4) Write a C program that reads in a string from the keyboard. Use scanf with...

4) Write a C program that reads in a string from the keyboard.
   Use scanf with the conversion code %s. Recall that the 2nd
   arg in scanf should be the address of the location in
   memory into which the inputted string should be stored. 
   Recall that the name of an array without square brackets is 
   the address of the first slot of the array.

5) Write a program that reads in this file (lab5.txt) and counts
   and displays the number of lowercase e's in the file. Use the
   fread function to read the entire file with just one call of fread.
   Use google to get info on fread.

Homework Answers

Answer #1

#include <stdio.h>

int main() {
    char str[100];
    printf("Enter a string: ");
    scanf("%s", str);
    printf("You entered %s\n", str);
    return 0;
}

#include <stdio.h>

int main() {
    char str[1000];
    int count = 0, i = 0;
    FILE *fp = fopen("lab5.txt", "r");
    if (fp) {
        fread(str, sizeof(char), 1000, fp);
        while (str[i]) {
            if (str[i] == 'e') {
                ++count;
            }
            i++;
        }
        printf("Number of e's in file is %d\n", count);
    } else {
        fclose(fp);
    }
    return 0;
}
Know the answer?
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
Similar Questions
Write a C program that reads in a float constant (use %f in scanf) and displays...
Write a C program that reads in a float constant (use %f in scanf) and displays its internal representation in hex. Use your program to check your answers to problem 1. Hint: a union is like a struct except that the fields overlap. Hint: the conversion code for hex is %x. union X { int a; float b; }; int main() { union X test; ... ; test.a and test.b refer to same word in memory but have ; different...
Write a program in C that does the following: Reads 10 real numbers from the keyboard...
Write a program in C that does the following: Reads 10 real numbers from the keyboard using a loop and displays the sum of the numbers and the sum of the square of the numbers.
Write an Assembler Program to input a string from the keyboard, store the string in memory....
Write an Assembler Program to input a string from the keyboard, store the string in memory. Your program should check and display if the string contains vowel letters (A, E, I, O, U), Hint: your program should check both lower and upper case
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
I am trying to write a program that reads a string (in my case a domain...
I am trying to write a program that reads a string (in my case a domain name). What I am struggling with is how to traverse through the array and see if there are any invalid characters in the string such as a semi colon or a space. Here is what I have as of now. #include <stdio.h> int main() {    char min[1];    char max[253];    char domain[253]; printf("Enter a domain: "); scanf("%s", domain);    return 0; }
Write an assembly program that reads characters from standard input until the “end of file” is...
Write an assembly program that reads characters from standard input until the “end of file” is reached. The input provided to the program contains A, C, T, and G characters. The file also may have new line characters (ASCII code 10 decimal), which should be skipped/ignored. The program then must print the count for each character. You can assume (in this whole assignment) that the input doe not contain any other kinds of characters.  the X86 assembly program that simply counts...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the user and places them in an array of type float. Once the numbers are stored in the array, the program should average and print the result. Use pointer notation wherever possible. Program Output (with Input Shown in Bold): Enter number: 2 Enter another (y/n)? y Enter number: 4 Enter another (y/n)? y Enter number: 6 Enter another (y/n)? y Enter number: 8 Enter another...
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
In C write a menu driven program to write your own string handling functions. Don’t use...
In C write a menu driven program to write your own string handling functions. Don’t use static arrays, ONLY dynamic memory allocation is allowed. 1. Convert a string to integer. 2. Concatenate two strings 3. Copy string to another string 4. Compare two strings 5. String length 6. Quit
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT