I wanted to know why not read the functions on the screen

Asked

Viewed 25 times

0

#include <stdio.h>

typedef struct { 
char titulo; 
char autor; 
float preco; 
} livro ;

livro definelivro(char titulo, char autor, float preco){
    
    livro l;
    l.titulo = titulo;
    l.autor = autor;
    l.preco  = preco;
    return l;
}

void mostrarnatela(livro l){
    printf("titulo: %c  autor: %c  preco: %f\n", l.titulo, l.autor, l.preco);
}

int main(){
    
    livro livro1;
    livro1 = definelivro("Crime e Castigo", "Dostoievski", 59.00);
    mostrarnatela(livro1);
    return 0;
}
  • what does "read screen functions" mean? You stated titulo and autor as char, a single letter. But called the function by passing for example "Crime and Punishment" that is const char[]. Here is the crime and the punishment: the compiler did not accept.

1 answer

1

Your functions are being read and are working, just calling your function definelivro, in Function main, that is not correct for what you defined in your program

You set at the beginning of your struct?

char titulo; 
char autor; 

if you call your function send a char where you declared your program works perfectly:

    livro1 = definelivro('C', 'D', 59.00);

Remember to use simple quotes :) in char setting

Using this function call the answer will be:

    titulo: C  autor: D  preco: 59.000000

Browser other questions tagged

You are not signed in. Login or sign up in order to post.