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

  • Home
  • SEARCH
  • 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 7182403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:45:49+00:00 2026-05-28T17:45:49+00:00

#include <stdio.h> FILE *fl; char content[BUFSIZ]; int main() { int i; fl = fopen

  • 0
    #include <stdio.h>

FILE *fl;
char content[BUFSIZ];

int main() {

  int i;

  fl = fopen ("data.txt", "rt");
  content = fgetc(fl);

  for (i=0;i <= sizeof(content); i++ ){
    printf("%c",content[i]);
  }

  fclose(fl);
}

I’m trying to open a file and put the content of the text file into content[] array. But when I tried to compile I get the following errors.

y:~/homework1: gcc -o hw1_2 hw1_2.c
hw1_2.c: In function 'main':
hw1_2.c:11:11: error: incompatible types when assigning to type 'char[1024]' from type 'int'
  • 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-28T17:45:50+00:00Added an answer on May 28, 2026 at 5:45 pm

    The function fgetc reads a single character and returns it. So you’re trying to assign a single integer to an array which isn’t going to work.

    You should be using fread for this.

    fread(content, 1, sizeof(content), fl);
    

    However, since you tagged it homework, you may want something like this:

    int ch;
    
    while (i < SIZE && (ch = fgetc(fl)) != EOF)
        content[i++] = ch;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include <stdio.h> int main () { FILE *fp; char ch; char data[100]; int i;
#include<stdio.h> #include<stdlib.h> int main() { int count=0; char c=0; printf(Reading this Source file\nFile name
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
Here is my code: #include<stdio.h> #include<stdlib.h> #include<sys/stat.h> #include<sys/types.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> int main(int argc,char
vi example.c #include<stdio.h> #include flite.h register_cmu_us_kal(); int main(int argc,char** argv) { cst_voice *v; if(argc!=2)
EDIT: void print(const int *v, const int size) { FILE *fpIn; fpIn = fopen(char-array.txt,
When I write the following program: file 1: #include <stdio.h> int global; void print_global1()
This is a simple code that open and print the file content. #include <stdio.h>
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits

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.