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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:43:15+00:00 2026-06-15T00:43:15+00:00

int main() { int a = 0; int BUFSIZE = 1000; char *string1[20]; FILE

  • 0
int main()
{
int a = 0;
int BUFSIZE = 1000;
char *string1[20];
FILE *fp1 = fopen("input1.txt", "r");
if (fp1 == 0)
{
    fprintf(stderr, "Error while opening");
    return 0;
}
string1[a] = (char *)malloc(BUFSIZE);
while (fgets(string1[a], BUFSIZE, fp1)!=NULL)
{
    a++;
    string1[a] = (char *)malloc(BUFSIZE);
} 
printf("%c", string1[3]);
}

Hi, I get the above code, which reads a string from a text file and store it in an array. Now I want to output a certain element of array string1, but apparently printf doesn’t work. Besides, what does char *string1[20] exactly define? Does it have something to do with pointer? Thank you!

  • 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-15T00:43:16+00:00Added an answer on June 15, 2026 at 12:43 am
    char *string1[20]
    

    declares an array, named string1, of 20 pointers to char. Thus string1[3] is a pointer to char, and not a char, as would be required for the %c format.

    Since string1[3] was – if at all – filled via fgets, it contains a 0-terminated string, so you can print it out using

    printf("%s\n", string1[3]);
    

    If you want to print a single character, you’d use

    printf("%c\n", string1[3][4]);
    

    for example.

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

Sidebar

Related Questions

#include <stdio.h> FILE *fl; char content[BUFSIZ]; int main() { int i; fl = fopen
Hey guys, here is my code. int main() { char buffer[BUFSIZE]; // define our
int main() { FILE *read_fp; char buffer[BUFSIZ + 1]; int chars_read; memset(buffer, '\0', sizeof(buffer));
int main(void) { char testStr[50] = Hello, world!; char revS[50] = testStr; } I
int main() { char *p,c; for(p=Hello World;c=*p;++p) { printf(%c,c); } } In the above
int main(void) { char *p = hello; char *q = world; *p = *q;
This is my code: #include <stdio.h> #include <string.h> #include <iconv.h> int main() { char
int readOptions(char *argv[]){ FILE * infile; char line_buf[BUFSIZ]; int i = 0, j =
#include <stdio.h> char converter(char input[]); char getInformation (char input[]); int main(){ char c[99]; int
code: #include <shlwapi.h> int main() { TCHAR buffer[MAX_PATH]; DWORD bufSize; GetModuleFileName(NULL, buffer, bufSize); TCHAR*

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.