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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:50:56+00:00 2026-05-27T03:50:56+00:00

#include <stdio.h> #include <stdlib.h> int main ( int argc, char *argv[] ) { //sets

  • 0
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] )
{
//sets the number of lines ot be read  
char strline[10000]; 
// checks to see that there are only 2 entries in the argv by checking in argc
if ( argc != 2 )
    {
        printf( "ERROR. Enter a file name\n", argv[0] );
    }
    else 
    {
       //opens the file which was entered by the user as read only 
       FILE *infile = fopen( argv[1], "r");
        // covers a miss spelling of a file name or file doesn't exist
        if ( infile == 0 )
        {
            printf( "ERROR. Did you make a mistake in the spelling of the file or the File entered doesn't exist\n" );
        }
        else 
        {
            // File exists read lines, while not at the end of the file
while  (!feof(infile))
                {   
//Get next line to be printed up to 126 characters per a line
if(fgets(strline, 126, infile))
            {
                //print the current line (stored in strline)
printf("%s",strline);
            }
        }
    //closes the file
fclose( infile );
    return 0;        
    }
    }
} 

On the 6th line (comment above) I have stated this is the maximum amount of lines the program can read. I was informed yesterday that this isn’t the case.

Can someone explain to me what the code line actually means?

char strline[10000]; 

So from what people have being saying what setting it to 128 make more snese (126 for fgets and some room)

  • 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-27T03:50:56+00:00Added an answer on May 27, 2026 at 3:50 am

    char strline[10000]; neans you have allocated a buffer that is 10,000 bytes long:

               +--------------...-+
    strline -> |      10000       |
               +--------------...-+
    

    if you wanted to allocate for 10,000 lines instead you would need something like this:

    char* strline[10000]; // array of 10,000 pointers to strings
    

    accessing lines would be to assign to each entry in the array

    strline[0]
    strline[1]
    ...
    strline[10000]
    

    like when a line is read you would need to allocate a buffer for the line and then point to it from strline

    char* line = malloc( linelength + 1 );
    fgets( line, linelength, fp );
    strline[0] = line;
    
                  +-------+
    strline[0] -> | line  |
                  +-------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code. #include<stdlib.h> #include<stdio.h> int main(int argc,char** argv) { char a; a=9;
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main (int argc, const char * argv[])
#include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { char *p[2]; char
cat main.c #include <stdio.h> #include <stdlib.h> #include <linux/ext2_fs.h> int main(int argc, char** argv) {
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, const char *argv[]) { srand(clock());
#include<stdio.h> #include<unistd.h> #include<stdlib.h> int main(int argc,char **argv) { int fd[2]; pid_t childpid; pipe(fd); childpid=fork();
#include <stdio.h> #include <stdlib.h> #include <string.h> int main ( int argc, char *argv[] )
C file: #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { FILE *ptr;
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
Here's what I have: #include <stdlib.h> #include <string.h> #include <stdio.h> int main(int argc, char

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.