Writing of text file with fixed and variable length

1

I do not understand what I am doing wrong with the writing of the text files, since I get many warnings. Can someone help me know what I'm bugging him about?

fread(&reg,1,sizeof(info),fp);
while(!feof(fp))
{
    fprintf(fpTextFijo,"%*ld%-*s%-*s%*f\n",SIZE_DNI,reg.dni,SIZE_NAME,reg.name,SIZE_SURNAME,reg.surName,SIZE_AVERAGE,reg.average);
    fprintf(fpTextVar,"%ld|%s|%s|%f\n",reg.dni,reg.name,reg.surName,reg.average);
    fread(&reg,1,sizeof(info),fp);
}


C:\Users\jorge\Desktop\Estructuras de datos\main.c||In function 'main':|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: conversion lacks type at end of format [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: field width specifier '*' expects argument of type 'int', but argument 4 has type 'long int' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: format '%s' expects argument of type 'char *', but argument 5 has type 'int' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: field width specifier '*' expects argument of type 'int', but argument 6 has type 'char *' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: format '%s' expects argument of type 'char *', but argument 7 has type 'int' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: field width specifier '*' expects argument of type 'int', but argument 8 has type 'char *' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: format '%f' expects argument of type 'double', but argument 9 has type 'int' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|36|warning: too many arguments for format [-Wformat-extra-args]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|37|warning: unknown conversion type character '|' in format [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|37|warning: format '%s' expects argument of type 'char *', but argument 3 has type 'long int' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|37|warning: format '%f' expects argument of type 'double', but argument 5 has type 'char *' [-Wformat=]|
C:\Users\jorge\Desktop\Estructuras de datos\main.c|37|warning: too many arguments for format [-Wformat-extra-args]|
    
asked by Jorge Gonzalez 27.11.2016 в 18:34
source

1 answer

1

You need to prepend a . in the specifier * .

Its correct use is: .*

Try modifying your line of code in the following way and several of your warnings should be solved:

fprintf(fpTextFijo,"%.*ld%-.*s%-.*s%.*f\n",SIZE_DNI,reg.dni,SIZE_NAME,reg.name,SIZE_SURNAME,reg.surName,SIZE_AVERAGE,reg.average);
    
answered by 28.11.2016 в 03:48