I made this header for some program functions:
#ifndef STRING_H_INCLUDED
#define STRING_H_INCLUDED
#include <stdio.h>
int s_length(char *test_string){ //returns string length
int i=0;
while(*test_string){
i++;
test_string++;
}
return i;
};
void s_insert(char *string_one){ //inserts string
scanf("%s",string_one);
};
void s_output(char *string_one){ //outputs string
printf("%s",string_one);
};
#endif
and I call the functions in the c file like 2 times each. But the last 2 of them get this: warning: implicit declaration of function ‘s_insert’
and undefined reference to 's_insert'
. for both functions.
What does this mean, and what did I do wrong?
It might have to do with the main c file in which I call the functions.
main progam:
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
char *name,*surname;
void menu(){
int choise;
do{
printf("1: incerici dati\n");
printf("2: output dati\n");
printf("3: calcola lungezza\n");
printf("0: ecsi\n");
printf("incerici: ");
scanf("%d", &choise);
printf("------------------\n");
switch(choise){
case 1:
printf("String 1:");
s_insert(name);
printf("String 2:");
s_insert(surname);
printf("------------------\n");
break;
case 2:
s_output(name);
s_output(surname);
printf("------------------\n");
break;
case 3:
printf("string 1: %s lungezza: %d \n",name,s_length(name));
printf("string 2: %s lungezza: %d \n",surname,s_length(surname));
printf("------------------\n");
break;
case 0:
printf("prgram closed!!\n");
break;
default:
printf("Errore: %d schelta invalida\n",choise);
break;
}
}while(choise);
};
int main(int argc, char *argv[]){
name=malloc(sizeof(char)*20);
surname=malloc(sizeof(char)*30);
menu();
return 0;
}
ps fot the people wondering, the printed text is italian because it's a school exercice.