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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:33:19+00:00 2026-06-09T16:33:19+00:00

I am an Android and Java developer and I am not much familiar with

  • 0

I am an Android and Java developer and I am not much familiar with C language. As well as you know there is not a String type in C. All I want is getting chars, putting them into an char array and writing these characters as a string. How can I take the whole string which is a array of characters and put it into a variable? This is my code but it does not work properly. The log which I get is:

I/        ( 2234): *********PROPERTY = 180000€¾Ü    €¾Ü €¾ 

It should have been 180000.

int c;
char output[1000];
int count = 0;
char *property;
FILE *file;
file = fopen("/cache/lifetime.txt", "r");
LOGI("****************FILE OPEN*************");
if (file) {
    LOGI("*****************FILE OPENED************");
    while ((c = getc(file)) != EOF) {
        putchar(c);
        output[count] = c;
        ++count;
        LOGI("******C = %c", c);
    }
    property = output;
    LOGI("*********PROPERTY = %s", property);
    fclose(file);
}
  • 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-09T16:33:20+00:00Added an answer on June 9, 2026 at 4:33 pm

    What you are missing is a '\0'. All strings in C are just a sequence of characters ending with a '\0'.

    So, once your loop

    while ((c = getc(file)) != EOF)
    

    is done, you can add the statement

    output[count] = '\0'
    

    Below modifications are needed if you intend to return the property variable outside the local function and if output is a variable local to the function.

    In the above below line will need modification

    property = output; 
    

    You should allocate memory for property using malloc and then use strcpy to copy the string in output to property or do a strdup as suggested by Joachim in the comment.

    Using strdup, the statement will be like below

    property = strdup(output); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m an Android developer, and recently started working on JAVA PC project for client.
I already know quite a few tricks with Android java and I have an
First, I'd like to let you know my experience. PHP - medium | Android/Java
I am fairly new to Android development as well as Java and i am
I am not a new developer to android. I have an application on the
How to read RSS Feed by using Java Script. As I am Android developer
Just for the disclaimer, I'm not trying to win the prize in Android Developer
I am new in android, I dont have that much of experience. I want
Based on http://developer.android.com/guide/topics/data/data-storage.html#db it seems like I'd need another Java Class file (which I
Not sure this is an android issue, I am a c++ developer trying to

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.