Question

****Using C language***** Assume you have an input file with 10 characters. Scan these values in...

****Using C language*****

  1. Assume you have an input file with 10 characters. Scan these values into an appropriate array.
  2. Convert all the characters into Upper Case, then find their ascii value (like done in the homework) and save to a new array, order these values from highest to lowest. Save to file called “upper.txt”
  3. Convert all the characters into Lower Case, then find their ascii value (like done in the homework) and save to a new array, order these values from highest to lowest. Save to file called “lower.txt”
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

// function prototye to sort
void highToLow(int arr[]);

int main()
{
   // opening file for input
   FILE* inputFile = fopen("characters.txt", "r");
   // checkikng file opening status
   if(inputFile == NULL)
   {
       printf("Cannot open file!\n");
       return 1;
   }
   // opening files for output
   FILE* upperFile = fopen("upper.txt", "w");
   FILE* lowerFile = fopen("lower.txt", "w");
   // checking opening status
   if(upperFile == NULL)
   {
       printf("Cannot open file!\n");
       return 1;
   }
   if(lowerFile == NULL)
   {
       printf("Cannot open file!\n");
       return 1;
   }

   char inputArr[10]; // array to store characters
   // scanning characters
   int i;
   for(i = 0; i < 10; i++)
   {
       fscanf(inputFile, "%c\n", &inputArr[i]);
   }

   int uppperArr[10]; // array to store ascii value of uppercase characters
   for(i = 0; i < 10; i++)
   {
       uppperArr[i] = (int)toupper(inputArr[i]);
   }
   // sorting lowest to highest
   highToLow(uppperArr);
   // writing to file
   for(i = 0; i < 10; i++)
   {
       fprintf(upperFile, "%d\n", uppperArr[i]);
   }
  
   int lowerArr[10]; // array to store lowercase ascii value
   for(i = 0; i < 10; i++)
   {
       lowerArr[i] = (int)tolower(inputArr[i]);
   }
   // sorting highest to lowest
   highToLow(lowerArr);
   for(i = 0; i < 10; i++)
   {
       fprintf(lowerFile, "%d\n", lowerArr[i]);
   }

   // closing all files
   fclose(inputFile);
   fclose(upperFile);
   fclose(lowerFile);

   return 0;
}

// function definiton
void highToLow(int arr[])
{
   int i,j;
   for(i = 0; i < 10; i++)
   {
       for(j = 1; j < 10-i; j++)
       {
           int temp;
           if(arr[j] > arr[j-1])
           {
               temp = arr[j];
               arr[j] = arr[j-1];
               arr[j-1] = temp;
           }
       }
   }
}

test.c × 1 #include <stdio.h> #include #include <stdlib.h> <ctype.h> 4 / function prototye to sort void highToLow(int arr[) 8

45 highToLow uppperArr): for(1-0; i < 10; i++) sorting lowest to highest writing to file 47 48 49 50 51 52 53 fprintf(upperFi

Characters.txt file

characters.txt x

OUTPUT

NOTICE: We've to print the upper.txt and lower.txt file after running the program

adnanli@euler1 /Desktop$ make test test.co adnanli@euler1:~/Desktop$ ./test adnanli@euler1:~/Desktops cat upper.txt 90 89 79

Add a comment
Know the answer?
Add Answer to:
****Using C language***** Assume you have an input file with 10 characters. Scan these values in...
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
  • Do it on (c) pls..... 1. Assume you have an input file with 6 integer values....

    Do it on (c) pls..... 1. Assume you have an input file with 6 integer values. Scan these values into an appropriate array. 2. Create a user defined function that takes your array as an input and order your array from lowest to highest. Ex. If you have an array called num, then num[0] should contain the smallest value while num[5] will contain the largest value. 3. Output the values between 50-75 into an output file called “results.txt” 4. Any...

  • You are provided with an input file called "sensor.txt" and a "code skeleton" of the exam questio...

    You are provided with an input file called "sensor.txt" and a "code skeleton" of the exam questions. The text file has 10 numbers. 1. You will scan the 10 values located in “sensor.txt” to an array of variable type double, using a loop of your choice. 2. You will create a user defined function that will take your array as an input and find the average value. (Ex. arr[] = {15, 12, 13, 10}, the sum will be 50 then...

  • use C++ programming language and follow the instruction carefully. thanks! Inputs: . [integer] values (10 times)...

    use C++ programming language and follow the instruction carefully. thanks! Inputs: . [integer] values (10 times) Outputs: • [integer) highest value . [integer] lowest value Description: Write a program that lets the user enter 10 values. These values should be stored in an array. Your program will then find the highest and lowest values in the array. Your program will display the list of number as a comma separated list, and print which values is the highest and lowest Do...

  • Write a C program that reads characters from a text file, and recognizes the identifiers in...

    Write a C program that reads characters from a text file, and recognizes the identifiers in the text file. It ignores the rest of the characters. An identifier is a sequence of letters, digits, and underscore characters, where the first character is always a letter or an underscore character. Lower and upper case characters can be part of the identifier. The recognized identifier are copied into the output text. b. Change the C program in exercise 2, so that all...

  • In C language This program reads in a series of words. All words consist of only...

    In C language This program reads in a series of words. All words consist of only lower-case letters ('a' through 'z'). None of the words entered will be longer than 50 letters. The program reads until ctrl-d (end-of-file), and then prints out all the lower-case letters that were missing in the input or a statement indicating the input has all the letters. Two executions of the program are shown below. Enter your input: the quick brown fox jumps over the...

  • Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array...

    Programming language --> Matlab The name of a text file Outputs: (cell) An Nx2 cell array listing words and their counts in sorted order Function Description: Have you ever seen those fancy word-clouds based on the frequency of word occurrences in some text? Well the first step of making a graphic like that is to figure out how often the words in some text occur, which is exactly what this function will do. You will count the number of occurrences...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • please use c++ please write down the input file information please add comments for some codes...

    please use c++ please write down the input file information please add comments for some codes please do not use #include <bits/stdc++.h> we did not learn it yet thank you CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and code a top-down modular program utilizing ARRAYS to solve the following problem, using at least 3 functions (called from the main() section or from another function) to solve the problem....

  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

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