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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:06:11+00:00 2026-05-28T04:06:11+00:00

I have a word file with 3 words. I need to read each word

  • 0

I have a word file with 3 words. I need to read each word into an array. I tried doing this with fscanf(), but it doesn’t work. What am I doing incorrectly?

#include <stdio.h>

void main(){
    char words_array[80];
    FILE *dictionary;
    dictionary = fopen("dictionary.txt", "r");
    fscanf (dictionary, "%s", words_array);
    printf("The content of words_array is: %s, %s, %s, \n", words_array[0], words_array[1], words_array[2]);
}

I get the following error when I try to compile:

warning: format ‘%s’ expects argument of type ‘* char’ but argument has type ‘int’

The dictionary.txt file is as follows:

apple
orange
bananna

Thanks all!

  • 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-28T04:06:12+00:00Added an answer on May 28, 2026 at 4:06 am

    Assuming you have only one word (fruit) in one line (and < 80 characters long) in the dictionary.txt, the following should work!

    #include <stdio.h>
    
    int main(void)
    {
        char words_array[80];
        FILE *dictionary;
        dictionary = fopen("dictionary.txt", "r");
        while (fscanf (dictionary, "%s", words_array) == 1) {
            printf("%s \n", words_array);
        }
    
        return 0;
    }
    

    Output:

    $ gcc fsca.c 
    $ ./a.out 
    apple 
    orange 
    bananna 
    $ cat fsca.c 
    

    Adding an alternative answer as per request from the OP author.

    #include <stdio.h>
    
    int main(void)
    {
        char word1[80], word2[80], word3[80];
        FILE *dictionary;
        dictionary = fopen("dictionary.txt", "r");
        fscanf(dictionary, "%s", word1);
        fscanf(dictionary, "%s", word2);
        fscanf(dictionary, "%s", word3);
        printf("%s %s %s\n", word1, word2, word3);
    
        return 0;
    }
    

    Output

    $ gcc fsca.c 
    $ ./a.out 
    apple orange bananna
    $ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file, of which i need each column, preferably into a
I have this text file that I read into a Java application and then
I have a xml file which I need to open with Microsoft Word 2007.
I have a classic ASP application which inserts some values into a word file
Hi I have a file try.SPEC. This file contains a word Version: 1.0.0.1 .
I need to read a line like this from a file: 5 Chair 12.49
I have this problem. I read with BufferedReader text from one system file, this
I'm not sure how to word this exactly but I have a script that
I have a peculiar problem. I need to read (from a txt file) using
I need to read in a text file of 500 words or more(a real

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.