Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 10, 2013, 03:50 PM   #1
Rudd999
macrumors newbie
 
Join Date: May 2013
Basic c programming help

hey guys, i dont get why i cant find a .txt file it so frustrating because i dont get why it cant find the file. i have tried it in all folders of the project and it just wont find it.

im using c btw :P

copy of the code:

Code:
{
	char ch, ch2;
	FILE *fp1, *fp2;
	fp1=fopen("MyEncryptedFileA.txt","r");
	if (fp1 == NULL)
	{
        printf("ERROR no file\n");
        ch = getchar();
        exit(1);
	}
	printf("File Decrypted.... \n");
	fp2=fopen("MyDecryptedFileA.txt","w");
    
	ch = fgetc(fp1);
	while(ch != EOF)
	{
        /* decryption algorithm a here */
        ch2 = ch - 10;
        /* end of decryption algorithm */
        fprintf(fp2, "%c", ch2);
        ch = fgetc(fp1);
	}
	fclose(fp1);
	fclose(fp2);
	printf("\n**********************\n");
	printf("\n\n");
}

Last edited by OllyW; May 10, 2013 at 04:35 PM. Reason: Please use code tags
Rudd999 is offline   0 Reply With Quote
Old May 10, 2013, 04:06 PM   #2
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
I find file handling to be a rather complicated topic that shouldn't be taught early on, mostly because programmers rarely need to handle files.

Having said that, what's the present working directory when your program is running?

Are you using Xcode? If so, you need to make sure that in your Build Phases the file you'd like to access in your program is copied. To access Build Phases, click on your project in the navigator (left panel of Xcode,) then on your target (next panel to the right that opens when you select it,) then select the "Build Phases Tab". You might need to add a new build phase of the type Copy Files. Drag in the file that you want copied. The destination should be "Products Directory" if I recall correctly. Make sure "Copy only when installing" is unchecked.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote
Old May 10, 2013, 04:14 PM   #3
Rudd999
Thread Starter
macrumors newbie
 
Join Date: May 2013
i dont know if this is going to help but thought it might show you what i have done so far :/ i have written the code myself and i understand how to write c but not how to link files in xcode
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-05-10 at 22.12.10.png
Views:	40
Size:	1.46 MB
ID:	411739  
Rudd999 is offline   0 Reply With Quote
Old May 10, 2013, 04:23 PM   #4
subsonix
macrumors 68030
 
Join Date: Feb 2008
Where is your "MyEncryptedFileA.txt" located? From the looks of it, not in your current working directory.
subsonix is offline   0 Reply With Quote
Old May 10, 2013, 05:03 PM   #5
Rudd999
Thread Starter
macrumors newbie
 
Join Date: May 2013
the program creates the file. that is the point :P it reads the MyFile.txt file, ascii by ascii and adds 10 to the amount and then writes the new ascii to the new MyEncryptedFileA.txt file.
Rudd999 is offline   0 Reply With Quote
Old May 10, 2013, 05:08 PM   #6
subsonix
macrumors 68030
 
Join Date: Feb 2008
Quote:
Originally Posted by Rudd999 View Post
the program creates the file. that is the point :P it reads the MyFile.txt file, ascii by ascii and adds 10 to the amount and then writes the new ascii to the new MyEncryptedFileA.txt file.
Right, you changed you code. Because your first version in post #1 sure attempts to opens the file for reading. Creating a caesar cipher, wouldn't you want to use any file as input?

Still, you need to set your working directory to where the file is located (the file you can not open, previously MyEncryptedFileA.txt).
subsonix is offline   0 Reply With Quote
Old May 10, 2013, 08:52 PM   #7
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Your cases don't match - that could be contributing to the issue. Your file (listed in the left sidebar) has camel case while in your code you have all lowercase letters. I'm not sure if fopen() is case sensitive but I'd say it's safer to guess it is and just match case just to rule that out as a potential issue.
ArtOfWarfare is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Programming on iPad with "smart BASIC" kibernetik iPad Apps 0 May 8, 2014 02:35 PM
Mac programming should be more like iOS programming. moonman239 Mac Programming 13 Feb 17, 2014 01:37 PM
Some help with some basic C Tander Mac Programming 8 May 10, 2013 08:58 AM
Free note app with basic formatting basic HTML Subu iPhone and iPod touch Apps 0 Mar 1, 2013 03:44 AM
Basic C Programming Question - Can anyone help? 007bond Mac Programming 3 Feb 6, 2013 12:15 PM

Forum Jump

All times are GMT -5. The time now is 05:06 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC