How do I access a .txt file in Xcode for an OSX command line tool?

I'm in school learning C and C++, and we have to read from and write to .txt files regularly. But I can't figure out how to open a .txt file in Xcode.
if FILE *buffer = fopen(filename,"r"); where filename is a pointer to a char array holding the name of the file, it works perfectly fine in the terminal. It compiles, in both Xcode and GCC, but when I try to actually open the file in Xcode, my program can never find it and quits the application (so it doesn't crash).
Long story short, what do I have to do to get my programs in Xcode to read from a .txt file?
I tried putting a copy of input.txt in every folder within the project, including it in the source files, adding it to target (which I don't wholly understand), I don't know what to do.

Make sure the filename has an absolute path. If the path is relative it will point to a different location depending on where you run the program from.
When you run it from within Xcode itself the binary is buried way inside the project hierarchy (you can see where it is by selecting the program in the  Products folder and doing a Show in Finder).
The safest bet is to always specify a specific directory for any writes you do.
regards
As an example for this program in Xcode (assumoing you will be able to see the images)
The binary is located here

Similar Messages

  • Security restrictions , how to read access a txt file supplied in a jar

    I had written a simple application which uses file handling to display random line from a file on a swing window
    but I do not know how to give my web application permission to access a file
    when I set security permission to all, then error says the application cannot load because the code require unrestricted acess to system resources and is unsigned, I don't know how to get that certificate and I am only doing it for learning purposes.
    when I remove security permissions then it says
    access denied java.io.FilePermissions geekjoskes.txt readPlease help
    I locally signed the jar file, and give my jnlp fiel all permissions, worked fine in my system but when I access same file from local lan it sho errors ,
    please help, I have my txt file stored in my jar file with main class
    the whole jnlp file is
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for geek jokes -->     
    <jnlp spec="1.0+"
           codebase="http://localhost/javasoft/webstart/"
          href="geekjokes.jnlp">
       <information>
          <title>Geek Jokes</title>
          <vendor>Vaibhav Mishra</vendor>
          <description>Geeky jokes</description>
          <homepage href="http://scjpbeginner.blogspot.com"/>
          <description kind="short">shows random jokes</description>
          <offline-allowed/>
       </information>
       <resources>    
            <jar href="GeekJokes0.1.jar"/>  
         <j2se version="1.6+"
               href="http://java.sun.com/products/autodl/j2se"/>
         <icon href="geekjokes.gif"/>
       <icon kind="splash" href = "geekjokes.gif"/>
       </resources>
       <security>
          <all-permissions/>
       </security>
       <offline-allowed/>  
       <application-desc main-class="GeekJokes"/>
    </jnlp>Edited by: 76jsr on Aug 7, 2008 3:45 PM
    Edited by: 76jsr on Aug 7, 2008 3:49 PM

    >
    I am extremely thankful to you and finally my first little app is working thanks to you,
    here is it's link
    [http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes/geekjokes.jnlp|http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes/geekjokes.jnlp] >
    I am glad you got it working! But that launch file is still slightly invalid.
    Here is a corrected, and slightly optimized (you can leave the prefix off the href, if it is the same as the codebase), version of it.
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for GeekJokes 0.3 app -->
    <jnlp spec="1.0+"
          codebase="http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes"
          href="geekjokes.jnlp">
       <information>
          <title>GeekJokes App</title>
          <vendor>Vaibhav Mishra</vendor>
          <homepage href="http://scjpbeginner.blogspot.com"/>
          <description>Geeky Jokes</description>
          <description kind="short">Cshows random jokes</description>
          <offline-allowed/>
       </information>
       <resources>
           <j2se version="1.6+"
               href="http://java.sun.com/products/autodl/j2se"/>
           <jar href="GeekJokes0.3.jar"/>
       </resources>
       <application-desc main-class="Process"/>
    </jnlp>Very 'Geeky', BTW. ;-)
    Another few things I noted when I looked at it.
    1) There is a stray thread going after the JOptionPane is dismissed. The VM does not end, and the console (if you have it configured to pop-up for JWS apps.) stays on-screen.
    2) If all the jokes are prefixed by '* ' I would recommend removing it from every line of the source file and either re-adding it at runtime, or (preferably) not adding it at all (since it is redundant).
    3) Reconfigure the app. into a loop, and offer the user a JOptionPane with "Another Joke"/"End" instead of "OK".
    4) You can always remove that debugging line I inserted in the code to show the path to the Jar - it was just intended as a 'sanity check' during testing.
    5) Why is it Java 1.6+? JOptionPane was introduced in Java 1.2 with the first Swing implementations, and the I/O is compatible with Java 1.1.
    >
    Thanks again!!!!>Thanks are best expressed (to me) in the notation of a helpful/correct answer (which you have done), and the assignation of (the remaining) dukes*. ;-)
    * After all - checks the title - we have gotten entirely around those 'security restrictions' in a sandboxed application. The reason being that File objects are rarely the correct choice, for applets or JWS apps.

  • How do I play an audio file in Xcode for Mac OS X?

    I have been looking and looking, and I still can't find out how I can play a sound in Xcode. I have done it for the iPhone, but I'm trying to do it for Mac OS X. I am a beginner and so I am going to need some explaining as to what is going on. I just need to play a short sound (max of 10 seconds) when a timer goes off. Any help is very greatly appreciated (I have been trying to get this to work for WEEKS)! Thanks in advance.

    https://developer.apple.com/mac/library/samplecode/PlayFile/Introduction/Intro.h tml
    Docs are your friend....mac os has it's own just like iPhone.

  • How to uninstall the command line tools?

    I installed the command line tools in Xcode 4.5 from the preferences : downloads : command line tools.
    If i want to uninstall this component, what should I do?
    PS:
    I saw an answer in the Apple Support Communities about how to uninstall the Xcode 4.3 and later versions.
    This is the original: " If You want to uninstall completely XCode go to launchpad and push Xcode icon for two
    seconds, so click on the upper left checkbox.".
    I don't know what means "push Xcode icon for two seconds, so click on the upper left checkbox".

    There is no easy way to uninstall the command line tools. The following article has a script to uninstall them:
    You Don’t Need The Xcode “Command Line Tools”
    Read the comments in the article. I have not tested the script, but this is the first result when searching Google for "xcode 4.5 uninstall command line tools".

  • I have converted a pdf to word. How can I access the Word file from my online account?

    I have converted a pdf to word. How can I access the Word file from my online account? When it says 'download the converted file' I choose a location on my PC and click, but nothing happens. It seems that it can only save the converted file to my online account. I went to my online account but I see no way to look for the file

    Hey Fabrizio,
    You might need to sign up at "https://cloud.acrobat.com/exportpdf" using your Adobe ID credentials to convert your PDF file to Word.
    Do you get the 'download' prompt?
    Also, you can find the converted files by clicking at the 'Files' tab. 
    Please try the same using a different browser and check.
    Hope to hear from you.
    Regards,
    Anubha

  • How do I access my iCloud files from my ipad?

    How do I access my iCloud files from my ipad?

    Try using the PC to launch www.icloud.com

  • How can i access filename from file (sender)

    hi All,
    can anybody tell me
    how can i access filename from file (sender)?
    thank u
    swari

    See:
    "SAP NetWeaver XI: Variable Substitution with Adapter-Specific Message Attributes via DynamicConfigurationBean"
    SAP NetWeaver XI: Variable Substitution with Adapter-Specific Message Attributes via DynamicConfigurationBean
    "Accessing Adapter-Specific Attributes through User Defined Function"
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/70c89607-e4d9-2910-7280-f6746e964516

  • How to get Text from (.txt) file to display in the JTextArea ?

    How to get Text from (.txt) file to display in the JTextArea ?
    is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...

    public static void readText() {
      try {
        File testFile = new File(WorkingDirectory + "ctrlFile.txt");
        if (testFile.exists()){
          BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
          String s = br.readLine();
          while (s != null)  {
            System.out.println(s);
            s = br.readLine();
          br.close();
      catch (IOException ex){ex.printStackTrace();}
    }rykk

  • How do I access my *.Nef files in finder and aperture?

    How do I access my *.Nef files in finder and aperture?  What are the key strokes to finding these files.
    BACKGROUND:       I shot jpg and nef during recent trips overseas, but can only see the jpg files in finder and aperture.  Are the original, the raw or NeF files?

    Kirby Krieger wrote:
    Unfortunately, that horse is in the clover.  The distinction would force "raw" to be understood as an adjective (which designates a family of image file formats) and not as an actual image file format, which in turn would help many better understand what raw camera files are.  Alas.  I suppose one could substitute "one of the raw file formats" in place of RAW.
    Alas indeed, Kirby. On the other hand, if mentioning it now and again *does* help someone understand the distinction, then I'll continue to mention it, um, now and again.
    And if it prompts someone to ask a question, all the better - I can then ride this particular hobbyhorse around the forum, slaying linguistic sloppiness in my path.
    That Apple are guilty of the same error is disappointing though. As you say, Alas...

  • In digital editions how to you access the pdf file on your computer - I want to read in acrobat

    in digital editions how to you access the pdf file on your computer - I want to read in acrobat as digital editions too hard to read.@@

    On Mac, try looking in:
    /Users/dug.geo/Documents/Digital Editions
    On Windows, look for "Digital Editions" in "My Documents". If it's not there, look one level above "My Documents".
    If you know the filename of the PDF, you could also try doing a file system search for it.

  • Retrieving .txt file from jar for an applet

    I guess this is a newbie question but i checked the tutorial sessions and i am doing exactly what it says there but still...no luck:
    I'm trying to access a .txt. file stored in the .jar file where my applet .class file is stored. I'm using:
    String s = "myfile.txt";
    // get current Class loader
    ClassLoader cl = this.getClass().getClassLoader();
    FileInputStream is = new FileInputStream((cl.getResource(s)).toString());
    BufferedReader in = new BufferedReader(new InputStreamReader(is));But when the applet is viewer from the browser or from the appletviewer, i'm getting the FileNotFoundException:
    java.io.FileNotFoundException: jar:file:\C:\FeatureSelection\sFeatureSelection.jar!\myfile.txt (The filename, directory name, or volume label syntax is incorrect)
    I tried to use the following instead:
    FileInputStream is = new FileInputStream((myApplet.class.getResource(s)).toString());orFileInputStream is = new FileInputStream((getClass().getResource(s)).toString());but the same exception is still there.
    The jar file and the html file are all stored in this directory C:\FeatureSelection\
    The signed jar file is called sFeatureSelection.jar
    Any help would be greatly appreciated!
    Thanks.

    One way to get at files in a jar is to put the jar in the CLASSPATH and then just refer to the resource by its path in the jar. If the same path occurs in two different jars, then you only get the first one, based on the order of the jars in CLASSPATH, I think.
    The classloader is involved, which can be confusing, but an easy way to try this is:
    String s = "myfile.txt";
    URL u = this.class.getClassLoader().getResource(s);
    Object o = u.getContent();Now, you only really know that something matched that path and now it is in a URL.
    I think the Object will be a stream and you have to read() it or something.
    BTW: I encourage you to examine the URL, but it is not necessary to do so.
    If you have somehitng like a GIF image, then here is an example of how to work with that:
    http://www.devx.com/tips/Tip/5697
    Here is a way to get the bytes without involved the ClassLoader:
    http://www.javaworld.com/javaworld/javatips/jw-javatip49.html
    Take your pick.

  • How to set up a basic file sharing server for my small architectural business?

    I have no idea if I have posted in the correct area as this is my first forum post within the apple support community!
    I have been using a 21.5" imac running 10.6.8 for the past 5 years to run my small home based architectural design business. I have been using the internal hard drive & backing up the necessary data to a simple usb external hard drive. I am now looking to firstly purchase a new imac 27" retina and purchase new autocad lt 2015 for mac software. I am looking to have another imac (my old mac) running in conjunction with the new mac. I want both macs to be able to access the same data and am slightly unsure what is the best way to achieve this.....As my old mac is currently only running snow leopard and an old version of autocad for mac 2011 it wont run on any more recent OS. Essentially i believe I have 2 main options with this.... (1) I Accept that I have to purchase 2 no. autocad lt 2015 licences @ a cost of £2300. Or option (2), I only run autocad on the new mac as this will be the primary station and the old mac used for primarily for admin & accounts. I have also recently discovered that it is possible to rent autocad licences for £300p/a which may also be another option (3)!
    I previously had a problem where my hard drive failed on my mac & lost all data on the internal hard drive, luckily I had been backing up all data regularly to my external hard drive and now loss occurred! Obviously with any new system I want to ensure that my data is safe!
    I currently utilise about 250GB of data for business operations but this will obviously grow with time.
    In the future I would like to have the option of potentially being able to access the network data remotely via macbook pro whilst abroad although at this stage this really isnt my primary objective. Although I believe I could achieve this through apple remote desktop.
    I suppose I should provide some information with regard to the required speed of the system...I regularly open 50-100 photos at the same time totalling around 250-500MB. I would like the system to be able to handle this fairly easily.
    I have been trawling through forums and to be honest they are totally confusing me. I have also spent time on the phone to the apple business team and have also discussed my objectives with a member of the apple team in store.
    There have been various options advised to me and I really do not know which is the most appropriate route forward.
    1 - Using a mac mini as the file server and linking the 2 mac devices to this and backing up the mac mini to an external hard drive to ensure no loss of data.
    2 - Using a time capsule as a file server and linking the 2 mac devices to this and backing up the TC to an external hard drive to ensure no loss of data.
    3 - Using the new mac hard drive and linking the 2 macs via thunderbolt (old mac does not have thunderbolt and so I guess I would need another new mac?!) and then backing up the data to a time capsule.
    4 - Using a RAID based server and linking the 2 no. macs.
    Sorry to ramble but any advice really would be greatly received!

    Hi sblemings,
    Welcome to the community.
    I think with your scenario you should ask yourself, how complicated do you want the setup to be and how much time would you have to be able to resolve an issue should one occur with this setup.
    All the options that have been advised would work but they come with complexity and therefore time.
    1 - Using a mac mini as the file server and linking the 2 mac devices to this and backing up the mac mini to an external hard drive to ensure no loss of data.
    2 - Using a time capsule as a file server and linking the 2 mac devices to this and backing up the TC to an external hard drive to ensure no loss of data.
    3 - Using the new mac hard drive and linking the 2 macs via thunderbolt (old mac does not have thunderbolt and so I guess I would need another new mac?!) and then backing up the data to a time capsule.
    4 - Using a RAID based server and linking the 2 no. macs.
    Sorry to ramble but any advice really would be greatly received!
    option 1
    Would be a way to achieve what you want, it would centralise your files and you would only need to backup your file server (as long as all the files you wanted backed up were on it). This could be achieved either using the client and sharing various folders or using Server which would give you more options than you would possibly need.
    option 2
    This is exactly like option 1 except that you wouldn't have to administer another mac however you may limit any future growth.
    option 3
    This option I probably wouldn't pick, you could achieve this with firewire and use a firewire to thunderbolt adapter (saves you having to buy a new iMac)
    option 4
    This option would, depending on your RAID level, give you disk redundancy but remember you would still need to back this up, as RAID is NOT a backup solution.
    I would also ask is there a pressing need to keep the old iMac in service and complicating things by having a server / NAS? Could you not just transfer all your information over to this and continue with the one backup? I would say that doing it this was would be the simplest way of achieving what you want from what I can take from your question.
    As for remotely accessing your data, if you have the right hardware the way to achieve this would be to use a VPN and connect back to your data. However a potentially easier way for you ,would be to use a service like logmein or teamviewer to connect back.
    Hope this helps, and by all means any questions please ask.
    Dan
    How to set up a basic file sharing server for my small architectural business?

  • How to create and use library JAR files with command-line tools?

    Development Tools -> General Questions:
    I am trying to figure out how to put utility classes into JAR files and then compile and run applications against those JAR files using the command-line javac, jar, and java tools. I am using jdk1.7.0_17 on Debian GNU/Linux 6.0.7.
    I have posted a simple example with one utility class, one console application class, and a Makefile:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130520-2134.tar.gz
    Here is a console session:
    2013-05-20 21:39:01 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-20 21:39:12 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/hello/HelloConsole.java
    package com.example.hello;
    import static com.example.util.Hello.hello;
    public class HelloConsole {
        public static void main(String [] args) {
         hello("world!");
    2013-05-20 21:39:21 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -f hello
    find . -name '*.class' -delete
    javac src/com/example/util/Hello.java
    javac -cp src src/com/example/hello/HelloConsole.java
    echo "java -cp src com.example.hello.HelloConsole" > hello
    chmod +x hello
    2013-05-20 21:39:28 dpchrist@desktop ~/sandbox/java/jar
    $ ./hello
    hello, world!I believe I am looking for:
    1. Command-line invocation of "jar" to put the utility class bytecode file (Hello.class) into a JAR?
    2. Command-line invocation of "javac" to compile the application (HelloConsole.java) against the JAR file?
    3. Command-line invocation of "java" to run the application (HelloConsole.class) against the JAR file?
    I already know how t compile the utility class file.
    Any suggestions?
    TIA,
    David

    I finally figured it out:
    1. All name spaces must match -- identifiers, packages, file system, JAR contents, etc..
    2. Tools must be invoked from specific working directories with specific option arguments, all according to the project name space.
    My key discovery was that if the code says
    import com.example.util.Hello;then the JAR must contain
    com/example/util/Hello.classand I must invoke the compiler and interpreter with an -classpath argument that is the full path to the JAR file
    -classpath ext/com/example/util.jarThe code is here:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130525-1301.tar.gz
    Here is a console session that demonstrates building and running the code two ways:
    1. Compiling the utility class into bytecode, compiling the application class against the utility bytecode, and running the application bytecode against the utility bytecode.
    2. Putting the (previously compiled) utility bytecode into a JAR and running the application bytecode against the JAR. (Note that recompiling the application against the JAR was unnecessary.)
    (If you don't know Make, understand that the working directory is reset to the initial working directory prior to each and every command issued by Make):
    2013-05-25 14:02:47 dpchrist@desktop ~/sandbox/java/jar
    $ cat apps/com/example/hello/Console.java
    package com.example.hello;
    import com.example.util.Hello;
    public class Console {
        public static void main(String [] args) {
         Hello.hello("world!");
    2013-05-25 14:02:55 dpchrist@desktop ~/sandbox/java/jar
    $ cat libs/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-25 14:03:03 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -rf bin ext obj
    mkdir obj
    cd libs; javac -d ../obj com/example/util/Hello.java
    mkdir bin
    cd apps; javac -d ../bin -cp ../obj com/example/hello/Console.java
    cd bin; java -cp .:../obj com.example.hello.Console
    hello, world!
    mkdir -p ext/com/example
    cd obj; jar cvf ../ext/com/example/util.jar com/example/util/Hello.class
    added manifest
    adding: com/example/util/Hello.class(in = 566) (out= 357)(deflated 36%)
    cd bin; java -cp .:../ext/com/example/util.jar com.example.hello.Console
    hello, world!
    2013-05-25 14:03:11 dpchrist@desktop ~/sandbox/java/jar
    $ tree -I CVS .
    |-- Makefile
    |-- apps
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.java
    |-- bin
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.class
    |-- ext
    |   `-- com
    |       `-- example
    |           `-- util.jar
    |-- libs
    |   `-- com
    |       `-- example
    |           `-- util
    |               `-- Hello.java
    `-- obj
        `-- com
            `-- example
                `-- util
                    `-- Hello.class
    19 directories, 6 filesHTH,
    David

  • How to send report output to  two  detinations at a time from command line?

    Hi ,
    how to send my report to two detinations at a time from command line i.e FILE and Mail ?
    i created batchfile in that i mentioned one line for file(DESTYPE=FILE) perpose and another line for mail perpose(DESTYPE=Mail).i don't want to mention to lines.
    i want to send my report out put two destinations at a time insted of running two times.
    thx in advance.....
    raghu

    hello,
    did you try to use distribution for that ? check out the reports distribution facilities available in 6i.
    regards,
    the oracle reports team

  • How do I run Safari with a proxy on start up by command line?

    Hello,
    I am using a piece of software called Sahi to perform automated testing of websites. It uses a local proxy to accomplish this task, so it runs the browser with parameters needed so that that instance of the browser is running with the proxy settings. For some reason it's not correctly setup by default with Safari on the Mac. But it has a configuration file where you can set the command line parameters that it runs the browser with.
    So when I use Sahi in its default configuration, it doesn't work because the proxy is not configured, and I get an error ( http://sahi.co.in/forums/discussion/4607/sahi-doesn039t-work-with-safari-5-0-1-o n-macosx )
    So I need to set the proxy. When I set the 127.0.0.1:9999 proxy in the System Preferences it works. My question is how do I run Safari so that it provides the proxy settings as a command line option?
    This way I can add the command line option to the Sahi configuration file so that it runs Safari properly. I don't want to have the proxy settings system wide because I need other programs to work. I don't want to have the proxy settings set for Safari permanently because I also need to be able to run Safari normally outside of this special context.
    Any assistance would be appreciated.

    I should mention this is Safari 5.0.1

Maybe you are looking for

  • PR close configuration

    Hii SAP, Where can i find the PR CLOSE configuration once PR is fully converted to PO ? i found out my PR can be converted to PO than my PO become double because of the PR is not close.

  • How to run a script op Indesign startup?

    Hi, I have a script that runs fine when manually running it in inDesign CC. Now i need that script to run automatically when a file is opend in InDesign. I put the script in "stratup scripts" folder. But get the error that there is no active document

  • Recuperar número de serie

    Tengo un problema con un número de serie de adobe creative suite, la persona que estaba antes de mi (sistemas) formateo la pc donde estaba instalado sin desactivar el producto que ahora pide licencia, no dejo la cuenta de adobe con la que se hizo la

  • About 10 kernel panics in the past 3 months - looking for cause

    Hello, I have tried searching extensively in the discussions.apple.com and in Google but cannot answer the question myself.  I've had quite a number of kernel panics in the past 3 months on a MacBook Pro 13" purchased new in July 2010. I'll post two

  • BAPI to trigger VF06 through a program and retrieve the net value

    I'm working on a report program where I provide the SD contract and the billing date and need to pull out the net values (with pricing done) . For this purpose , is it feasible to trigger VF06 proforma runs for the contracts using any standard BAPI ?