Basically what I'm trying to do is prompt the user for an input file and read in all of the characters in that file (assume <10000 chars), with the rule that all uppercase be converted to lowercase and all non-letter characters (! ^, ?, @) be excluded. What I have done so far is read in all the characters to a file (including non-letters and uppercase) and now I am trying to figure out how to modify that array so that I have only what I need left. Here is the code for this (used file test.txt for this and only <30 chars but the principle is the same I think. Also output the ascii values to a seperate file to check, files attached):
Code:
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#include<ctype.h>
int main () {
FILE *ifp = fopen("test.txt", "r");
FILE *ofp = fopen("testvals.txt", "w");
int i, size, count;
char chars[30];
//This if statement I don't really understand, it was something I picked up from the internet
//and it seems to work
if (fseek (ifp, 0, SEEK_END) == 0) {
size = ftell(ifp);
fseek (ifp, 0, SEEK_SET);
}
int ascii[size];
//Scan all the characters into an array
for (i=0; i<size; i++) {
fscanf(ifp, "%c", &chars[i]);
}
printf("\n");
//convert all chars in arraay to thier ASCII values
for (i=0; i<size; i++) {
ascii[i] =toascii(chars[i]);
}
for (i=0; i<size; i++) {
fprintf(ofp, "ASCII value %c= %d\n", chars[i], ascii[i]);
}
/* This is my idea if what I might need to do next, but I dont know how
to "skip" an array index without leaving it blank, is it possible to
delete an index?
for (i=0; i<size; i++) {
if (ascci[i] >= 0 && ascii[i]<=64) {
count+=1;
}
else if (ascii[i] >= 91 && ascii[i]<= 96) {
count+=1;
}
else {
ascii[i] = final[i];
}
}
*/
// printf("size = %d", size);
fclose(ifp);
fclose(ofp);
system("PAUSE");
return (0);
}
I included in the code comments my ideas about where to go next, but there could be a much better way to do this (hence why I'm here haha) and I'm stuck where I'm at. Thanks in advance for the help!
test.txt
testvals.txt
test.c