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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:47:57+00:00 2026-05-31T20:47:57+00:00

this is my struct typedef struct { char mmsi[10]; char name[20]; double latitude; double

  • 0

this is my struct

   typedef struct {
        char mmsi[10];
        char name[20];
        double latitude;
        double longitude;
        int course;
        double speed;
    }Vessel;

this is my function which doesnt want to work

void searchByLatLong(double latitude, double longitude){
        FILE * file;
        struct dirent *drnt;
        DIR * dir = opendir("./text");
        char *path = (char *)malloc(19);
        Vessel *vessel = (Vessel *)malloc(sizeof(Vessel));

        while((drnt = readdir(dir)) != NULL) {
            if(strcmp(drnt->d_name,".") && strcmp(drnt->d_name,"..")) {

                strcpy(path,"text/");
                strcat(path,drnt->d_name);

                file=fopen(path, "r");
                fscanf(file," %s %[a-zA-Z0-9 ]19s %lf %lf %d %lf", &vessel->mmsi,&vessel->name,&vessel->latitude,&vessel->longitude,&vessel->course,&vessel->speed);

        //  if (mmsi+".txt" == drnt->d_name){
                    printf("%s\n%s\n%lf\n%lf\n%d\n%lf\n\n",vessel->mmsi,vessel->name,vessel->latitude,vessel->longitude,vessel->course,vessel->speed);
            //}


            fclose(file);
        }
        seekdir(dir, telldir(dir)); 

    //  if(this->mmsi == mmsi){
        //  printVessel();
    //  }

    }
    closedir(dir);
}

When i try to load txt file it loads only two first strings then after it theres some rubbish from memory. Loading the data to another variables changes nothing ;/
This is a sample txt file which should be loaded:

3
RMS Titanic
22.222
33.333
4
5.9
  • 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-31T20:47:58+00:00Added an answer on May 31, 2026 at 8:47 pm

    The problem is with your format string. The correct format string is:

    " %s %19[a-zA-Z0-9 ] %lf %lf %d %lf"
    

    The field width goes before the conversion specifier. Also, the […] sequence is a conversion specifier, just like ‘s’. The problem you’re seeing is that fscanf() processes the ‘3’ because it matches the first %s. Then it processes the ‘RMS Titanic’ because it matches %[a-zA-Z0-9 ] but then processing stops because there is no ’19s’ in the input. At this point the remaining arguments are uninitialized.

    You should check the return value from fscanf(). It will tell you how many conversions were actually performed.

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

Sidebar

Related Questions

I have an array like this: typedef struct INSTR { char* str; int argc;
I have this struct: #define sbuffer 128 #define xbuffer 1024 typedef struct{ char name[sbuffer];
I have this struct typedef struct grade { char firstName[SIZE]; char lastName[SIZE]; int stuNum;
I have a struct like this typedef struct bookStruct { char title[80]; char author[80];
Let's say I have a first structure like this: typedef struct { int ivalue;
This is my c++ struct (Use Multi-Byte Character Set) typedef struct hookCONFIG { int
I am curious why this code works: typedef struct test_struct { int id; }
#include <iostream> using namespace std; typedef struct { char streetName[5]; } RECORD; int main()
Basically, I have lots of differently typed structs like this: typedef struct { char
I have this class which has a double list template of a struct of

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.