Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

467
Vistas
Creating a file using fopen()

I am just creating a basic file handling program. the code is this:

#include <stdio.h>
int main()
{
FILE *p;
p=fopen("D:\\TENLINES.TXT","r");
if(p==0)
{
    printf("Error",);

}

fclose(p);
}

This is giving Error, I cannot create files tried reinstalling the compiler and using different locations and names for files but no success. I am using Windows 7 and compiler is Dev C++ version 5

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Change the mode argument in fopen(const char *filename, const char *mode) from:

p=fopen("D:\\TENLINES.TXT","r");//this will not _create_ a file
if(p==0)                //  ^

To this:

p=fopen("D:\\TENLINES.TXT","w");//this will create a file for writing.
if(p==NULL)             //  ^   //If the file already exists, it will write over
                                //existing data.

If you want to add content to an existing file, you can use "a+" for the open mode.

See fopen() (for more open modes, and additional information about the fopen family of functions)

over 4 years ago · Santiago Trujillo Denunciar

0

According to tutorial, fopen returns NULL when error occurs. Therefore, you should check if p equals NULL.

Also, in printf("Error",);, omit the comma after string.

over 4 years ago · Santiago Trujillo Denunciar

0

You should be able to open the file, but you need to make it first. Make a txt document with the name res.txt. It should be able to write your result into the text document.

<?php
  $result = $variable1 . $variable2 "=" .$res ."";

echo $result;

$myfile = fopen("res.txt", "a+") or die("nope");

fwrite($myfile, $result);

fclose($myfile)
?>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda