0

when I try to use those functions it sends this error:

main.cpp: In function ‘int main()’:
main.cpp:11:17: error: conversion from ‘int’ to non-scalar type ‘fpos_t {aka _G_fpos_t}’ requested
main.cpp:18:20: error: cannot convert ‘fpos_t {aka _G_fpos_t}’ to ‘FILE* {aka _IO_FILE*}’ for argument ‘1’ to ‘int fgetpos(FILE*, fpos_t*)’

The code is:

#include<stdio.h>

struct registro{
        char nombre[5];
        };

int main()
{
FILE *fp;
registro datos[5];
fpos_t posicion=5;

fp = fopen("nombres.txt","w"); //CREA UN ARCHIVO DE TEXTO

printf("ingrese nombre: ");
gets(datos[1].nombre);

fgetpos(posicion,fp);
fwrite(&datos[1],5,1,fp); //ESCRIBE EL VALOR DE DATOS EN FP, CON UN TAMAÑO DE 5
fflush(stdin);
fclose(fp);
}

If you see any error please help.

1
  • All i want is a program that starts writting the text after a certain position... but i just cant get it to work
    – Rafa Mena
    Oct 23, 2013 at 15:31

1 Answer 1

0

Looks more like a stackoverflow kind of question but anyway, from what I can get from the error message, the problem is with the posiciion=5 part of the code. You are assigning an integer to a non-integer type fpos_t and that is causing both errors. try it without =5 and see if it works.

2
  • i gave up, this is the new code: #include<stdio.h> int main(){ FILE *fp; fpos_t position=; fp = fopen("file.txt","w"); fsetpos(fp,&position); fputs("This isnt working",fp); fclose(fp); } all i want is to creat a file where the text starts at position 10. I already did what you said, to delete =5 and it compiled.. but well, the text started from the begining, how can i get it to start at a designed position?
    – Rafa Mena
    Oct 23, 2013 at 15:28
  • I really suggest you post your coding related question on SO, other than me not really knowing how to help, it is not the most convenient way to do that here in comments. Really sorry :(
    – arsaKasra
    Oct 23, 2013 at 17:47

Not the answer you're looking for? Browse other questions tagged .