delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/21/20:52:44

From: buers AT gmx DOT de (Dieter Buerssner)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: append to a file
Date: 21 Feb 2000 19:46:24 GMT
Lines: 50
Message-ID: <88s4mf$1lgb0$1@fu-berlin.de>
References: <38b17e92$0$82782 AT SSP1NO17 DOT highway DOT telekom DOT at>
NNTP-Posting-Host: dialup-212.162.0.239.frankfurt1.mik.net (212.162.0.239)
Mime-Version: 1.0
X-Trace: fu-berlin.de 951162384 1753440 212.162.0.239 (16 [17104])
X-Posting-Agent: Hamster/1.3.13.0
User-Agent: Xnews/03.02.04
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

dos DOT fire AT aon DOT at (Florian X) wrote in 
<38b17e92$0$82782 AT SSP1NO17 DOT highway DOT telekom DOT at>:

>I want to append 128Byte on a file, so I open with
>
>char string[126];
>FILE *f = fopen(file, "a");
>fprintf(f,"TAG%-125s", string);
>fclose(f);
>
>Why doesn't it write anything to file?

Your example is not complete. Are string and file initialized?
Is file of type (const) char *? Did you check for f != NULL after
the call to fopen?

It works here:

E:\test>cat fopen.c
#include <stdio.h>

int main(void)
{
  char string[126] = "string";
  FILE *fp;

  fp = fopen("dum.txt", "w");
  if (fp == NULL)
    return 1;
  fprintf(fp, "1st line\n");
  fclose(fp);

  fp = fopen("dum.txt", "a");
  if (fp == NULL)
    return 1;
  fprintf(fp,"TAG%-125s", string);
  fclose(fp);
  return 0;
}

E:\test>gcc -O fopen.c

E:\test>a

E:\test>cat dum.txt
1st line
TAGstring

Regards,
Dieter

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019