Hello, everyone.
I have a program that has a struct like this:
struct itemDeLista{
char nomeProd[10];
float quant;
float vUnit;
int item;
};
But I need to count the number of letters in the stringProdName [10], as the teacher asked us not to use the string.h I'm doing the strlen function in a library of my own, I'm getting the char by scanf but when I step into the function of the library, some errors happen. I'll put the whole code.
#include <stdio.h>
#include <stdlib.h>
#include "biblio.h"
struct itemDeLista{
char nomeProd[10];
float quant;
float vUnit;
int item;
};
struct itemDeLista valores;
int main(){
int k = 0;
scanf("%[A-Z a-z]",valores.nomeProd);
printf("%s\n", valores.nomeProd);
k = strcnt(valores);
printf("%d", k);
return(0);
}
This is the main program, the following is the library and function to count the number of characters.
#include <stdlib.h>
#include <stdio.h>
int strcnt(struct itemDeLista m);
int strcnt(struct itemDeLista m){
int i = 0, cont = 0;
while(1){
if(m.nomeProd[i] != '#include <stdio.h>
#include <stdlib.h>
#include "biblio.h"
struct itemDeLista{
char nomeProd[10];
float quant;
float vUnit;
int item;
};
struct itemDeLista valores;
int main(){
int k = 0;
scanf("%[A-Z a-z]",valores.nomeProd);
printf("%s\n", valores.nomeProd);
k = strcnt(valores);
printf("%d", k);
return(0);
}
'){
cont++;
}
else{
break;
}
i++;
}
return(cont);
}
Thank you very much for the help, thanks!