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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:45:26+00:00 2026-06-15T21:45:26+00:00

I am trying to write from file to structure in C. Whenever I try

  • 0

I am trying to write from file to structure in C. Whenever I try to assign value in structure it gives me error: incompatible types in assignment.

My structure looks like this:

struct competition{
char eventTitle[79];
char date[79];
char time[79];
};

Basically I want to open the file and assign individual line to different value in structure. ie. first line in file -> eventTitle, second line -> date, third line -> time.

Here is how I try to assign it:

FILE *naDaSt;
char *mode = "r";
int lines = 0;
char line[79], current[79];


naDaSt = fopen(nameDateStart, mode);
if(naDaSt == NULL){
    printf("Can't find the files.");
    exit(1);
}else{
    struct competition comp, *p;
    p = ∁
    while(fgets(line, 79, naDaSt)){
        lines++;
        if(lines == 1){
            p->eventTitle= line;
        }
        if(lines == 2){
            p->date = line;
        }
        if(lines == 3){
            p->time = line;
        }
    }
}    

}

Could anyone help me?

  • 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-15T21:45:27+00:00Added an answer on June 15, 2026 at 9:45 pm

    Root Cause:

    You cannot do this:

            p->eventTitle = line;
            p->date = line;
            p->time = line;
    

    You are trying to assign arrays using assignment which cannot be done, arrays need to be copied. The compiler rightly reports the error:

    error: incompatible types in assignment
    

    because indeed the type you are trying to assign are incompatible.

    Solution:

    Instead, You need to use strcpy and copy the character arrays and not assign them.

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

Sidebar

Related Questions

I'm trying to create a XML structure (not read/write from/to a file, only the
I'm trying to write a file from an Http post reply to a file
I am trying to write a txt file from C# as follows: File.WriteAllText(important.txt, Convert.ToString(c));
I am trying to write my spatial data from a table to a file.
I'm trying to find a way to write to a text file from as2.
I'm trying to write a file from my Java program, but nothing happens. I'm
im trying to write a program that reads from a text file into a
I'm trying to write a windows batch file that can delete files from subdirectories.
I am trying to read a binary file from a program that writes a
I'm trying to retrieve folders name from a zip file. I wrote this simple

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.