I keep getting a compiler error whenever I try to use functions

Pritt Balagopal

I'm learning C, and we have been recently been taught functions. User defined functions strike me as fascinating, and so I decided to write a simple program to try out how a function works. Here's my code:

#include"stdio.h"

int main()
{
    func();
}
func()
{
    printf("This program uses a function.");
}

I pressed "compile" and I got a compliler error. The exact message it gave me is:

fpermissive]
func()
^
Return code is not 0

The diagnostics do not imply a mistake in the code that I wrote, so I'm unable to find out where I made a mistake. Can someone help me fix this program, and also successfully learn how to use user defined functions?

Edit:

I had forgotten to mention the return type of the function. I did that now, and here's my modified code:

#include"stdio.h"

int main()
{
    func();
    return 0;
}
int func()
{
    printf("This program uses a function.");
    return 0;
}

I pressed compile again, and got a different error message. This one says:

was not declared in this scope
func();
^
Return code is not 0

Can someone help me?

Aditi Rawat

You need to take care of two things: (a) Declaring func() before main() , (b) mentioning the return type of func().

#include<stdio.h>

void func(void); //forward declaration

int main()
{
    func();
}
void func(void) //specifying return type as **void**
{
    printf("This program uses a function.");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Syntax error whenever i try to use sys.stderr

I keep getting a error with this program. After getting the date in the compiler the error prompts and I'm unsure as to how to fix it

I am having an error whenever I try to add this

I keep getting IndexOutOfBounds error when I try to split a line from a file

HostnameValidation error whenever i try to use with flask-wtf

Whenever I try to compile javascript code I get a syntax error

When i try and migrate my tables in laravel i keep getting the following error

I keep getting an error when I try to pass the head pointer of the linked list

I get an error whenever I try to add myself to sudoers

I get an error whenever I try to connect database

Why do I keep getting this error when I try to sequence my actions in Swift?

Getting an error in the Email textbox whenever i try to SignUp using a Site for testing

I keep getting a -1700 error

I keep getting errors when I try to use JavaScript array methods

i'm getting error whenEver i try to get data from my db using this function(i'm using kotlin with android studio)

What is this error whenever I try to install mysql for python module?

I keep getting an error when I try to import tkFileDialog

I get an error whenever i try to use mysqldump in PHP. How can I properly import it and use it?

getting this error when i try to use the elif key word please

when I try to add files to the changelist I keep getting error files not in files(s) not in client view

Docker throwing ERROR: unsatisfiable constraints whenever I try to build GetTogether

Why am I getting a syntax error whenever I try to run VS code python terminal?

Why do I keep getting an error when I try to download only the audio of a Youtube video using pytube?

getting error when I try to use Drivers in CodeIgniter

I keep getting an error every time i try to calculate the diameter

I'm trying to use OPENPYXL, I get this TYPE ERROR whenever i try to create an excel file

I keep getting " Uncaught TypeError: dispatch is not a function" whenever I try to use dispatch using useContext hook

Getting: typeError: .create is not a function whenever I try to pass data to database

i keep getting the "list' object has no attribute 'find_element'" error whenever i try to use find_element after using find_elements