Originally Posted by
Raismans
"Write a program which calculates length of a string entered by user, up to 10symbols, calculation and user input should be done in separate functions"
Code:
int input(){
char str[E];
scanf("%s", str);
return (str);
}
You are returning a string but the function has the return type int.
"calculation and user input should be done in separate functions"
Maybe so . . . One more option.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAX 100
char *eingabe(void);
void laenge(char *str);
int main(void)
{
char *text;
text = eingabe();
laenge(text);
return(0);
}
char *eingabe(void)
{
char text[MAX];
char *str;
printf("\nText eingeben: ", str);
fgets(text, MAX, stdin);
return strtok(text, "\n");
}
void laenge(char *str)
{
int j;
char text[MAX];
strcpy(text, str);
j = strlen(text);
printf("\nLaenge des Textes %d Zeichen.\n", j);
}