Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:04:59+00:00 2026-05-24T23:04:59+00:00

Hello guys I’m writing a test file for a program. where all the possible

  • 0

Hello guys I’m writing a test file for a program. where all the possible numbers are tested and i want the result to be logged as a .csv file,so i can upload it into excel.

float calc (float i, float j , float p, float ex){

    float nodalatio = (p/ex); 

    float ans = (0.68 *j + 1.22*nodalatio + 0.34*j -0.81);

    return ans;

}  

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   float stage , grade, pos, ex;
    float resul;


    for (int i=1;i<=3;i++){
        stage = i;

        for(int j=1;j<=3;j++){
            grade = j;
            for(int p=1;p<=60;p++){
                pos = p;
                for(int e=1;e<=60;e++){

                    ex=e;
                    resul = calc(stage, grade,pos,ex);
                    NSLog(@"stage is %f grade is %f,pos is %f ex is %f the result is %f",stage,grade,pos,ex,resul);



                }

            }

        }
    }
    [pool drain];
    return 0;
}

the above is the test code and i can’t seem to figure how to output this in to a .csv file. does the code in the loop or after the loop. this is what i had but this did nothing !

NSString *file_path = @"test.csv";
NSString *test_1 = [NSString stringwithformat@"%f",resu];
[test_1 writeToFile:file_path atomically:YES encoding:NSUnicodeStringEncoding error:nil]; 

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:05:00+00:00Added an answer on May 24, 2026 at 11:05 pm

    Try this:

    float calc(float, float, float, float);
    
    float calc (float i, float j , float p, float ex)
    {
        float nodalratio = (p / ex); 
        float ans = (0.68 * j + 1.22 * nodalratio + 0.34 * j - 0.81);
        return ans;
    }  
    
    int main (int argc, const char * argv[])
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        float stage , grade, pos, ex;
        float resul;
    
        [[NSFileManager defaultManager] createFileAtPath: @"test.csv" contents: [@"" dataUsingEncoding: NSUnicodeStringEncoding] attributes: nil];
        NSFileHandle *file = [NSFileHandle fileHandleForWritingAtPath: @"test.csv"];
        [file seekToEndOfFile];
    
        for (int i = 1; i <= 3; i++)
        {
            stage = i;
            for(int j = 1; j <= 3; j++)
            {
                grade = j;
                for(int p = 1; p <= 60; p++)
                {
                    pos = p;
                    for(int e = 1; e <= 60; e++)
                    {
                        ex = e;
                        resul = calc(stage, grade, pos, ex);
    
                        NSString *str = [NSString stringWithFormat: @"%f, %f, %f, %f, %f\n", stage, grade, pos, ex, resul];
                        [file writeData: [str dataUsingEncoding: NSUTF16LittleEndianStringEncoding]];                 
                    }
                }
            }
        }
    
        [file closeFile];
    
        [pool drain];
        return 0;
    }
    

    That works for me. It will contain a proper BOM and write each string in UTF-16 (Unicode). Using other encodings, like NSUTF16StringEncoding, will write a BOM for each line, which is not really what you want.


    FWIW, are you sure it is not 0.68 * j and 0.34 * i or vice versa?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Guys I simply want to ask that is it possible to deploy Silverlight
Hello Guys! I want to create a site with a multiple file uploading through
Hello Guys I am working WPF app and I want to retrive all the
Hello guys first of all apologize for asking such a simple and yet redundant
Hello guys. I think it isn't possible just using PHP, but just to be
Hello guys, I have a general design problem with iPhone application. I want to
Hello guys I'm stucked in a point and I need your help. I want
Hello struggling here guys.. Is it possible to string replace anything between the the
Hello guys I am currently parsing all the html body for finding the document
Hello guys. I trying set EditText to input only numbers and point ( .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.