I have been checking on others letter count programs and none so far are like mine so I'm now making my own thread. My assignment, which is due tomorrow! *Yikes* Is for me to make a text file in notepad and then important that to my code. Then, I has to ask the user to input a letter, then have my code count how many times that letter came up in my text file. My text file that I have attached is test.txt. Keep in mind, this is my first, and sorry, attempt at this. Here's what I have so far..
#include<stdio.h>
#include<string.h>
int main(int argc, char *argv[]) {
printf("ECE 15 Assignment 2 \n");
printf("My name \n");
FILE *fin;
fin = fopen(argv[1], "r");
int numlet, n;
int h;
char c;
printf("Which letter would you like me to count in my text?: ");
c = getchar();
fin = fscan(argv[1], c) = h;
printf("The letter inputed: %c happened %d times", c, h);
return 0;
}
Also, heres the skeleton to what my prof said I should have.
Comment "skeleton" for Assignment 2:
// Print: ECE 15 Assignment 2
// Print: Names of partners; end each name with \n
// Loop
// Open argv[1]
// Prompt user and read character
// If no character, break out of loop
// Initialize counter to 0
// Loop until end of file
// if characters match add 1 to counter
// Close file
// Print output line to user
// End of program
Thanks for any help guys, I'll be checking this site every 5 mins or so.