简体   繁体   中英

Unresolved external symbol referenced in main

I have to create a program that has a function charster() that accepts three arguments: a character and two integers. It will print he character input x number of times per y number of lines. I am getting syntax error LNK2019 and LNK1120 Unresolved external symbol referenced in main. And IDK what I have done to cause this or what to do to correct it.

Here is my code:

#include <stdio.h>

void charster(char n, int n_char, int n_lines);

int main(void)
{
    char n;
    int n_lines, n_chars;

    printf("Please enter a character to be printed, the amount of times it should appear, and the amount of lines that should appear: ");

    while (scanf("%c, %d, %d", &n, &n_chars, &n_lines) == 3)
    {
        charster(n, n_chars, n_lines);
    }
    return 0;


    void charster(char n, int n_char, int n_lines);
    {
        int count; 

        for (count = 0; count < n_lines; count++)
        {
            putchar(n);
        }
    }
}

Firstly C language does not support nested functions. So you have to write the function charster() outside the main function.

You can write it above or below the main function as prototype is already declared.

Kindly have a look at the following code:

#include<stdio.h>

void charster(char n, int n_char, int n_lines);

int main(void)
{
    char n;
    int n_lines, n_chars;

    printf("Please enter a character to be printed, the amount of times it should appear, and the amount of lines that should appear: ");

    while (scanf("%c %d %d", &n, &n_chars, &n_lines) == 3)
    {
        charster(n, n_chars, n_lines);
    }
    return 0;
}

void charster(char n, int n_char, int n_lines)
{
    int times; 
    int lines;
    for (lines = 0; lines < n_lines; lines++)
    {
        for(times=0;times<n_char;times++){
            printf("%c ", n);
        }
        printf("\n");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM