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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:56:17+00:00 2026-06-11T03:56:17+00:00

The following code is written to select some data from one file and copy

  • 0

The following code is written to select some data from one file and copy into another, but I am getting error “Incompatible types in assignment” at notified position.I am unable to figure out what is causing this error. I will be glad to get your assistance.

#include <stdio.h>
#include <stdlib.h>

int main()
{
     FILE *myfile;
     myfile=fopen("write.txt","a");

char *name;
int id,i=0,check,*w,n=0;
if(myfile)
{
  do
  {
    printf("Enter ID and Name of the student\n");
    scanf("%d%s",&id, name);
    fprintf(myfile,"%d$ %s@", id, name);
    printf("Are there any more students [y/n]");
  }while(getch()=='y');
  fclose(myfile);
}
printf("Do you want to shortlist the students [y/n]?");
if(getch()=='y')
{
    myfile=fopen("write.txt","r");
    while(check!=EOF)
    {
        check=getc(myfile);
        i++;
        if(check=='%')
            n++;
    }
    fclose(myfile);

    myfile=fopen("write.txt","r");

    int x[i-1];
    char car[n][20];

    int yolo,y=0,q=0,j,h,temp;

    for(j=0;j<i;j++)
    {
        x[j]=getc(myfile);
        if(x[j]=='$')
        {
            w[q]=x[j-1];
            yolo=temp=j;
            q++;
        }
        else
        if(x[j]=='@')
        {
            yolo++;
            for(h=0;h<j-temp;h++)
                car[y]=(char)x[yolo]; // ERROR
            y++;
        }
    }
    fclose(myfile);
    //char data= new char[i++];
    //fscanf();
    myfile=fopen("shortlisted.txt","a");

    if(myfile)
    {
        printf("Type the ID of the student you want to shortlist:\n");
        scanf("%d",id);
    }
}
else
    printf("The file you specified doesn't exists");
printf("Hello world!\n");
return 0;

}

This code needs a little work at the moment but I want to remove all possible error before finalizing the code

Regards

  • 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-11T03:56:19+00:00Added an answer on June 11, 2026 at 3:56 am

    car[y] is an array of chars whereas (char)x[yolo] is just a char. You’re trying to assign a char to an array of chars.

    If you want to set the first character in car[y] to the value of x[yolo], just use car[y][0] = (char)x[yolo]. Note that that won’t convert x[yolo] into a char representation of an int. To get a char * representation of an integer, you’ll want to use itoa. But even then, a straight assignment won’t work: you’ll have to use strcpy.

    EDIT: it has been brought to my attention that it’s better to use sprintf than itoa.

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

Sidebar

Related Questions

I've written the following code to display some data, but the data grid is
I written the following code to randomly select items n items from a list
I have written a T-SQL script that migrates some data from one database to
Following on from my last question : I've written some code to upgrade a
I have following code written to run NSTimer . But the NSTimer selector is
I'm using some not optimal code written by me... :-| I have following code:
I'm trying to use the following code (poorly written, but it's just a proof
I have written a following code to get just the file name without extension
I have written some jquery code to select the div which is grandchild of
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];

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.