| | |
file opening problem!!!!!
![]() |
•
•
Join Date: May 2009
Posts: 7
Reputation:
Solved Threads: 0
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.
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.
C Syntax (Toggle Plain Text)
#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; }
1
#2 28 Days Ago
you can't do this:
you have to specify what you're testing for each OR'ed condition.
C Syntax (Toggle Plain Text)
if (ch == *my_word ||*my_word2 || *my_word3)
you have to specify what you're testing for each OR'ed condition.
C Syntax (Toggle Plain Text)
if (ch == *my_word || ch == *my_word2 || ch == *my_word3)
1
#3 28 Days Ago
Also you are not writing C++ code so all your variable definitions need to be at the top of your functions, before any executable statements.
And for us to follow your code, use proper formatting
And for us to follow your code, use proper formatting
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: May 2009
Posts: 7
Reputation:
Solved Threads: 0
0
#4 27 Days Ago
can u have at it again pls and sorry about any mistake again.
Br.
Br.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <ctype.h> #include <stdlib.h> int main(void) { int ch; long int pos; int NumAlpha = 0, NumDigit = 0, NumLower = 0, NumUpper = 0; int Count = 0, Place = 0; char *my_word, *my_word2, *my_word3; const char readerfilepath[500] = "D:\\TEMP\\readObject.txt"; const char writerfilepath[500] = "D:\\TEMP\\writeObject.txt"; my_word = "dog"; my_word2 = "cat"; my_word3 = "rat"; 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*/ if (ch == *my_word ||ch == *my_word2 || ch == *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); fclose(ipfileptr); fclose(opfileptr); return 0; }
![]() |
Similar Threads
- XP explorer slow opening files (Windows NT / 2000 / XP)
- file opening problem (C++)
- Batch File...please help!! (Legacy and Other Languages)
- Very Strange Windows File System Problem (Windows NT / 2000 / XP)
- File access problem (PHP)
- how to download a file without opening file download dialog box (Java)
Other Threads in the C Forum
- Previous Thread: Basic arithemetic on rational numbers
- Next Thread: Microsoft Visual studio Runtime
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. lowest match matrix microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h






