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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:56:39+00:00 2026-06-13T04:56:39+00:00

Since I’m very new to C programming, I have a probably very simple problem.

  • 0

Since I’m very new to C programming, I have a probably very simple problem.

I got a struct looking like this

typedef struct Vector{
    int a;
    int b;
    int c;
}Vector;

Now I want to write an array of Vectors in a file. To achieve that, I thought to create following method scheme

String createVectorString(Vector vec){
    // (1)
}

String createVectorArrayString(Vector arr[]){
    int i;
    String arrayString;
    for(i=0; i<sizeof(arr); i++){
        //append createVectorString(arr[i]) to arrayString  (2)
    }
}

void writeInFile(Vector arr[]){
    FILE *file;
    file = fopen("sorted_vectors.txt", "a+");
    fprintf(file, "%s", createVectorArrayString(arr);
    fclose(file);
}

int main(void){

    // create here my array of Vectors (this has already been made and is not part of the question)
    // then call writeInFile

    return 0;
}

My main problems are at (1), which involves also (2) (since I have no clue how to work with Strings in C, eclipse is saying “Type “String” unknown”, although I included <string.h>)

So I read at some point that transforming an int to a String is possible with the method itoa().
As I understood it, I can simply do following

char buf[33];
int a = 5;
itoa(a, buf, 10)

However, I cannot bring that to work, let alone that I can’t figure out how to “paste” chars or ints into a String.

In my point (1), I would like to create a String of the Form (a,b,c), where as a, b and c are the “fields” of my struct Vector.

In point (2), I would like to create a single String of the Form (a1,b1,c1)\n(a2,b2,c2)\n...(an,bn,cn), whereby n is the amount of Vectors in the array.

Is there a quick solution? Do I confuse the concept of Strings from Java with them of C?

  • 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-13T04:56:40+00:00Added an answer on June 13, 2026 at 4:56 am

    Yes, you do confuse the concept of strings in Java and C.

    The C strings are rather inconvenient to work with. They require dynamic memory allocation, and what is worse, corresponding deallocation (which is possible but tedious). In your case, it might be best to remove strings completely, and implement whatever you need without strings.

    To write a vector directly to file:

    Vector vec;
    FILE* file = ...;
    fprintf(file, "%d %d %\n", vec.a, vec.b, vec.c);
    

    To write an array of vectors, just do the above in a loop.

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

Sidebar

Related Questions

since they have same rendering engine, this problem shows in both. it works great
Since Sharepoint Foundation does't have integration services for InfoPath, I'm looking for a simple
Since I have no errors I don't know if this is the right place
Since hours I am working on a very hard problem: How is a DataGrid
Since I started this new webshop for a friend to launch, which still in
Since i'm not strong in asp.net, probably my question will sound silly. I've got
since I got python on windows running, here is the next problem I encountered
Since I'm using gtk3 and gtkmm3 on embedded I would like to have the
since today im facing a strange problem. When i start my app in my
Since now I have only used plugin for editing and the way I use

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.