| | |
file opening problem!!!!!
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 10
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 Oct 26th, 2009
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 Oct 27th, 2009
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: 10
Reputation:
Solved Threads: 0
0
#4 Oct 27th, 2009
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
Views: 219 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest homework i/o ide include infiniteloop initialization interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming spoonfeeding stack standard strchr string student suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32 win32api windows.h






