hi!
i'm trying to write the code to open the file and read the contents and write to another file with uppercase but the problem i'm having is path problem everything seems pretty fine but it says Steam != NULL , as long as i know its could'nt locating the file.
NB: i'm using Visual C++ 2008 as IDE.
Please have a look at it and correct me if i'm wrong.
Br.
#include "stdafx.h"
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(void)
{
int ch;
int NumAlpha = 0, NumDigit = 0, NumLower = 0, NumUpper = 0, Count = 0, Place = 0;
char *my_word, *my_word2, *my_word3;
my_word = "dog";
my_word2 = "cat";
my_word3 = "rat";
long int pos;
const char readerfilepath[500] = "D:\\TEMP\\readObject.txt";
const char writerfilepath[500] = "D:\\TEMP\\writeObject.txt";
FILE *ipfileptr;
FILE *opfileptr;
ipfileptr = fopen(readerfilepath, "r");
if (ipfileptr == NULL )
{
printf("Reader File not opened!\n");
exit(8);
}
else
{
printf("Reader File opened successfuly!\n");
}
opfileptr = fopen(writerfilepath, "w+");
if (ipfileptr == NULL )
{
printf("Writer File not opened!\n");
exit(8);
}
else
{
printf("Writer File opened successfuly!\n");
}
while ((ch = getc(ipfileptr)) != EOF){
if (isalpha(ch))
NumAlpha++; /* add 1 to NumAlpha count */
if (islower(ch))
NumLower++; /* add 1 to NumLower count */
else
if (isupper(ch))
NumUpper++; /*add 1 to NumAlpha count */
else
if (isdigit(ch))
NumDigit++; /*add 1 to digit count*/
//ch = putc(toupper(ch),opfileptr);
if (ch == *my_word ||*my_word2 || *my_word3){
Count++;
if((pos = ftell(ipfileptr)) != EOF){
Place++;
}
}
ch = putc(toupper(ch),opfileptr);
}
printf("\nNumAlpha = %d NumDigit = %d NumLower = %d NumUpper = %d\nCount = %d\nPosition = %d\n", NumAlpha, NumDigit, NumLower, NumUpper ,Count,Place);
// getchar();
fclose(ipfileptr);
fclose(opfileptr);
return 0;
}