How can I count the length of the word by strlen

I'm the beginner and I'm learning C++ .My teacher order me to make a program to find the longest name and I can't do it help me .(When I ask my teacher he always say only where I should change but I forget how to correct it.)
read my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<string.h>
main()
{
     int c;		int	n=0;	char s;		int m=0;
      printf("People Amount : ");
      scanf("%d",&c);
      char k[c]; int u=0;	int l[c];
      while(u<c)
      {
      			printf("Name : ");
                scanf("%strlen",&k[u]);
                u++;
      }  
      while(n<c)
      {
      	l[n]=strlen(k[n]);
      	n++;
	  }
      		n=0;
      	  while(n<c)
      {
                 if(l[n]>m)
                 {
                           s=k[n];
                           m=l[n];
                 }
                 n++;
	  }
	  printf("The longest name is ");
	  printf("%c",s);
    getch();    
Last edited on
http://www.cplusplus.com/reference/string/string/length/

This references how to use the string::length function. There are better ways to write this code and I would recommend getting the name into a string first. string name = "Zachary";
Then use the string length function to count how many letters are in your string. name.length();
My program can count many people so one name won't enough
I think
Topic archived. No new replies allowed.