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 8022055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:09:47+00:00 2026-06-04T22:09:47+00:00

I am making a simple command line tool where the user enters a username

  • 0

I am making a simple command line tool where the user enters a username and password (I don’t care about encryption
as this is only an exercise) and their age and this data is written to a file. This is the code I have:

    char username[40];
    char password[40];
    int age = 0;
    NSString *path = [NSString stringWithFormat:@"%@/Documents/config.txt", NSHomeDirectory()];
    NSFileManager *fileManager = [[NSFileManager alloc]init];

    //Username Input
    NSLog(@"Pick a username (less then 40 letters):");
    scanf("%s", username);
    NSString *usernameString = [[NSString alloc] initWithBytes:username
                                                            length:39 
                                                          encoding:NSUTF8StringEncoding];

    //Password Input
    NSLog(@"Pick a password (less then 40 letters):");
    scanf("%s", password);
    NSString *passwordString = [[NSString alloc] initWithBytes:password
                                                        length:39 
                                                      encoding:NSUTF8StringEncoding];
    //Age Input
    NSLog(@"What's your age?");
    scanf("%i", &age);

    NSString *finalContents = [NSString stringWithFormat:@"%@\n%@\n%i", usernameString, passwordString, age];
    NSData *dataContent = [finalContents dataUsingEncoding:NSUTF8StringEncoding];
    [fileManager createFileAtPath:path contents:dataContent attributes: nil];

When I open up the file produced, it has the content:

(null)
(null)
18

I inputted a string less then 40 characters for both the username and password and the number 18 for the age, so it appears that only the age is working.
Thanks in advanced.

EDIT: The file has the content “(null) (null) 18” with line breaks in between, but they are not showing up in my post.

  • 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-06-04T22:09:48+00:00Added an answer on June 4, 2026 at 10:09 pm

    Try using stringWithCString:encoding:.

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

Sidebar

Related Questions

My problem can be summed up by making this simple command works : nice
I'm making a simple command line Hangman game. void Hangman::printStatus() { cout << Lives
I am interested in making a simple command line utility ( in C )
I'm making a java command line program. How can I change the contents of
I want to make a simple program. Don't really care what it does, actually.
There are several libraries like ncurses that assist in making command-line GUIs. Simply put,
I am making simple connection between two table - first one called users has
Im making a simple alternative to the default linux system monitor. Im looking to
in making a simple cgi server for a course. To do that in some
I'm making a simple MVC component for joomla following the hello world tutorial for

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.