![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 1
| Help! Code: #include <stdio.h>
main() {
int Name_Array[10]; /* Creates a variable with 10 indexes */
char Name [10] [25]; /*Creates a char with up to 25 indexes */
gets (Name);
int i=0;
while (i<11) /* Creates a loop while "i" is less than 11 */
{
i=(i+1)
printf ("\nEnter name", Name_Array[i]);
scanf (%s, Name [i] [0-25]);
}
int str_len [10];
str_len [1]= strlen (Name_Array [1]);
str_len [2]= strlen (Name_Array [2]);
str_len [3]= strlen (Name_Array [3]);
str_len [4]= strlen (Name_Array [4]);
str_len [5]= strlen (Name_Array [5]);
str_len [6]= strlen (Name_Array [6]);
str_len [7]= strlen (Name_Array [7]);
str_len [8]= strlen (Name_Array [8]);
str_len [9]= strlen (Name_Array [9]);
str_len [10]= strlen (Name_Array [10]);
}
a)compress the strlen portion into a few lines b)get the program to take the str_len array with the highest value and print it.... Thanks! Last edited by Callumagus; 05-21-2008 at 12:21 PM. |
| Callumagus is offline | |
| | #2 |
| Registered User Join Date: Sep 2006
Posts: 2,511
| Please edit your post and remove the excess width inside your code tags. That's called "breaking the forum tables", and genuinely hated, since it's a constant aggravation to scan back and forth to read your post. Thanks. You don't need this large an array at all. You need two things: the current name being entered, and the longest name which has been entered, so far. That's it. Every name that is entered is checked inside the while loop, and if it is longer than the previously longest name, then it replaces it in that role. Last edited by Adak; 05-20-2008 at 03:22 PM. |
| Adak is online now | |
| | #3 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| Code: >while (i<11) /* Creates a loop while "i" is less than 11 */
>
> {
>
> i=(i+1)
> printf ("\nEnter name", Name_Array[i]);
> scanf (%s, Name [i] [0-25]);
>
> }
Code: #include <stdio.h>
#include <string.h>
.
.
for (i=0; i<10; i++) /* Creates a loop while "i" is less than 10 */
{
printf ("Enter name: ");
fflush(stdout);
scanf ("%25s", Name[i]);
}
__________________ http://www.freechess.org |
| swoopy is offline | |
![]() |
| Tags |
| error, names, program |
| Thread Tools | |
| Display Modes | |
|