0
By the enunciation of the exercise, I must use as the second argument char **strings
, I believe that there is my confusion, in manipulating her to count the size of string. (I did other tests with the second argument as char strings[][str_size]
and everything went well, but as I said, I need to use the argument as being char **strings
.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define str_size 127
void imprimeTamString(int numStrings, char **strings)
{
int i, j;
int tamanho;
printf("\n---Tamanhos---\n\n");
for(i=0; i<numStrings; i++)
{
tamanho=0;
for(j=0; j<str_size; j++)
{
if(strings[i][j]!='\0')
tamanho=tamanho+1;
else
break;
}
printf("String %d - Tamanho = %d\n", i+1, tamanho);
}
}
int main()
{
int n;//numero de strings//
printf("Deseja entrar com quantas strings? ");
scanf("%d", &n);
char *str1, **str2;
char string[n][str_size];
int i;
for(i=0; i<n; i++)
{
printf("String %d = ", i+1);
fflush(stdin);
gets(string[i]);
}
str1=string[0];
str2=&str1;
imprimeTamString(n, str2);
return 0;
}
And is there some restriction not to use the
strlen()
?– Maniero
No, but I also could not do using strlen()
– Marco Antonio Schneider
Call with: printTamString(n, string); you will be calling the function with a pointer to a char pointer.
– anonimo
@Marcoantonioschneider and has to be
char**
? Some reason to be yes: You’re not interpreting it this way but it might be another?– Maniero