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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:58:32+00:00 2026-06-14T06:58:32+00:00

I have a problem with getting every other line empty on output with this

  • 0

I have a problem with getting every other line empty on output with this code. The desired output is: http://paste.ubuntu.com/1354365/

While I get: http://paste.ubuntu.com/1356669/

Does anyone have an idea of why I’m getting these empty lines on every other line?

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

FILE *fp; 
FILE *fw; 


int main(int argc, char *argv[]){
char buffer[100];
char *fileName = malloc(10*sizeof(char));
char **output = calloc(10, sizeof(char*));
char **outputBuffer = calloc(10, sizeof(char*));

fw = fopen("calvin.txt", "w+");

for(int y = 0; y < 6; y++){
    for(int i = 0; i < 10; i ++)
    {
        output[i] = malloc(100);
    }

    for(int x = 0; x < 12; x++){
        sprintf(fileName,"part_%02d-%02d", x, y);
        fp = fopen(fileName, "rb");

        if(fp == NULL)
        {
            printf("Kan ikke åpne den filen(finnes ikke/rettigheter)\n");
        }
        else if(fp != NULL){

            memset(buffer, 0, 100); 
            for(int i = 0; i < 10; i++){ 
                outputBuffer[i] = malloc(100);
            }


            fread(buffer, 1, 100, fp); 


            for(int i = 0; i < 100; i++){
                if(buffer[i] == '\0')
                {
                    buffer[i] = ' ';
                }
                else if(buffer[i] == '\n')
                {
                    buffer[i] = ' ';
                }
            }
            for(int i = 0; i < 10; i++) { 
                strncpy(outputBuffer[i], buffer + i * 10, 10);

                strncat(output[i], outputBuffer[i]+1, 11);


            }                       
        }

    }

    for(int i = 0; i < 10; i++){
        printf("%s\n", output[i]);

    }

}
fclose(fp);
free(fileName);

}
  • 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-14T06:58:33+00:00Added an answer on June 14, 2026 at 6:58 am

    You are not reading correcting from the file. On the first image in the beginning you have:

          o ""oo    " o o o
    

    on the second

          ""oo     o o o
    

    That does not make a lot of sense because it is the first line. It is not related to empty lines since we are talking about the first line.

    It seems that you are reading -2 characters from the left so ” prints over o the other ” on the ‘ ‘ ect..

    Try this away, may not be the most efficient solution:

    int read(char *file)
    {
         FILE *fp = NULL;         
         int size = 0, pos = 0,i;
         fp = fopen(file,"r");
         if (!fp) return 0;
    
         for(; ((getc(fp))!=EOF);  size++); // Count the number of elements in the file
    
         fclose(fp);
    
    
         char buffer[size];
    
         fp = fopen(file,"r");
    
         if (!fp) return 0;
    
         while((buffer[pos++]=getc(fp))!=EOF); // Saving the chars into the buffer
    
         for(i = 0; i < pos; i++)              // print them.
           printf("%c",buffer[i]);
    
        fclose(fp);
        return 1;  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem getting my newly created php project on Netbeans work on
I have a problem getting the height of a (the one in the code
I just started a graphical C++ course and I have problem getting an overview
I have a problem getting password_Reset_confirm bit working. url: (r'^password_reset/$', 'django.contrib.auth.views.password_reset'), (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), (r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
I have a problem getting the right Price for a product based on Effectivity
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic and
I'm using jqGrid and I have a problem getting Dynamic Linq to work. I
I have a strange problem getting the color of the point that was touched.
I have a problem with getting my pager-function to work. For some reason it

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.