Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a new program (hw6-pr1) meeting at least the following minimum requirement

ID: 3863466 • Letter: W

Question

Write a new program (hw6-pr1) meeting at least the following minimum requirements: Opens the text version of this file (hw6-Spring2017.txt) and searches thru the file for the first occurrence of each of the 26 uppercase characters of the alphabet (A-Z), then each the 10 digits (0-9), and finally each of the 26 lowercase characters of the alphabet (a-z). As it finds each of these characters it should also record its position in the file (assume the first character in the file is in position 1). If the character or digit is not found in the file then it should be recorded as "Not Found" Display (5 per line) each of the alphanumeric characters (in the same order the search was done) immediately followed by its location in the file. Use exactly 10 columns to display each character/location pair as follows: character, 1 space, 6 digit location with no leading zeros, 2 spaces. For "Not Found" characters display location as NotFnd. Display (5 per line) each of the alphanumeric characters (in the order they were found in the file) immediately followed by its location in the file. Use exactly 10 columns to display each character/location pair as follows: character, 1 space, 6 digit location with no leading zeros, 2 spaces. "Not Found" characters should be displayed at the beginning of the list with location shown as NotFnd. Write a new program (hw6-pr2) meeting at least the following minimum requirements: Prompt the user to enter a string of 9 characters consisting of 4 digits (0-9), followed by a period (.), followed by 4 more digits (0-9), e.g. 1234.5678. Be sure to check for a correctly formatted input. Convert the input string into two integers (one from the first 4 digits and one from the last 4 digits) and one double (from the entire string). Display the resulting values (all on one line). Display each of the two integers in the following formats: decimal, octal (starting with "0") and hexadecimal (starting with "0x"). Put all 3 versions of each integer on the same line in columns 10 characters wide (i.e. use two lines of display for the two integers). Display the double in the following formats: default float, fixed and scientific. Put all 3 versions of the double on the same line in columns 20 characters wide. Do this twice, first with the default precision, and then using a precision of 8. Capture each of the four lines displayed above (two integer version lines and two double version lines) into a string and then display the string. The displayed lines should be identical to those previously displayed.

Explanation / Answer

#include<stdio.h>

int pos[62] = {0};
void readFile(char *fileName)
{
       FILE *file;
   char code;
   int localPos = 0;
   file = fopen(fileName, "r");
   do
   {   localPos++;
       code = (char)fgetc(file);
       if (code >='A' && code <= 'Z') {
           if (pos[code-'A'] == 0)
               pos[code-'A'] = localPos;
       }
       else if (code >='0' && code <= '9') {
           if (pos[code-'0' + 26 ] == 0)
               pos[code-'0' + 26 ] = localPos;
       }
       else if (code >='a' && code <= 'z') {
           if (pos[code-'a' + 36 ] == 0)
               pos[code-'a' + 36 ] = localPos;
       }
       } while(code != EOF);
}


void printStat() {
   int i;
   char ch;
   for (i = 0; i < 62; i++) {
       if (i < 26)
           ch = 'A' + i;
       else if (i < 36)
           ch = '0' + i - 26;
       else
           ch = 'a' + i - 36;
       if (pos[i] == 0)
           printf("%c NotFnd ",ch);
       else
           printf("%c %6d ",ch, pos[i]);
       if (i % 5 == 4)
           printf(" ");
   }
}


int main() {
   readFile("charPos.c");
   printStat();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote