Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

473
Views
Creando un archivo usando fopen()

Solo estoy creando un programa básico de manejo de archivos. el codigo es este:

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

Esto está dando un error, no puedo crear archivos, intenté reinstalar el compilador y usar diferentes ubicaciones y nombres para los archivos, pero no tuve éxito. Estoy usando Windows 7 y el compilador es Dev C++ versión 5

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Cambie el argumento de modo en fopen(const char *filename, const char *mode) de:

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

A esto:

 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.

Si desea agregar contenido a un archivo existente, puede usar "a+" para el modo abierto.

Ver fopen() (para más modos abiertos e información adicional sobre la familia de funciones fopen)

over 4 years ago · Santiago Trujillo Report

0

Según el tutorial , fopen devuelve NULL cuando se produce un error. Por lo tanto, debe verificar si p es igual a NULL .

Además, en printf("Error",); , omita la coma después de la cadena.

over 4 years ago · Santiago Trujillo Report

0

Debería poder abrir el archivo, pero primero debe hacerlo. Cree un documento txt con el nombre res.txt. Debería poder escribir su resultado en el documento de texto.

 <?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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!