Use xcode to read text files (txt files) on virtual machines)

Source: Internet
Author: User

I used to be engaged in VC ++ development. Now I have switched to iPhone development because of the needs of the project.

First install a virtual machine, and then install xcode.

I wrote a hello World program. It is okay to generate it.

Next, use the same project to write a program to read text files. The code is very simple, similar to that below VC, as shown below:

NSAID utoreleasepool * Pool = [[NSAID utoreleasepool alloc] init];

// Insert code here...
File * txtfile = fopen ("1.txt"," R ");
Char word [100];
If (nil = txtfile)
{
Nslog (@ "file is not exist! ");
Return 0;
}
While (fgets (word, 100, txtfile ))
{
Word [strlen (Word)-1] = '\ 0 ';
Nslog (@ "% s is % d character long", word, strlen (Word ));
}

Fclose (txtfile );
[Pool drain];
Return 0;

After running the final result for half a day, I did not find 1.txt. But is 1.txt clearly under the project folder? There is no problem with the code below in VC ++. Why is there a problem here?

Then I thought, do I need to put it in the build directory? However, no build is found under the stored directory. Therefore, the default directory generated by xcode is as follows:

/Users/user name/library/developer/xcode/deriveddata/product name-fylcrwghjxojxcgaejhixgwinhus/build/products/debug

The Chinese Mac OS directory is

User/your user name/resource library/developer/xcode/product name-fylcrwghjxojxcgaejhixgwinhus/build/products/debug

Then put the file in the DEBUG directory and run the program again. The result is displayed as normal.

You can change the directory generated through system preference settings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.