こんにちは、コマンドライン引数として「./prog7x hello there」が入力された場合、次のように表示するプログラムを作成しています。
argument 0 is "./prog7x", has length 8, contains 5 alphabetic characters
argument 1 is "hello", has length 5, contains 5 alphabetic characters
argument 2 is "there", has length 5, contains 5 alphabetic characters
Total length 18: ./prog7xhellothere
アルファベットの数え方に困っています。長さを取得する関数がありますが、長さを計算した後にカウントされた文字を表示する方法がわかりません。これまでのプログラムは次のとおりです...コーディングを始めてまだ数か月しか経っていないので、アドバイスをいただければ幸いです。 !
#include <cctype> //isalpha
#include <cstdio>
#include <cstring> //strlen
#include <cstdlib>
//Function to display what argument we're on
void displayArgument(char* arr1[],int num);
//Funtcion to get the length of a command line argument then,
//display number of alphabetical characters it contains
void displayLength(char* arr[],int length);
//Function to count the total length, concatenate together,
//and display results
//void displayTotalCat(char* arr2[],int total);
int main(int argc, char* argv[])
{
displayArgument(argv,argc);
displayLength(argv,argc);
return 0;
}
//Function to display what argument we're on
void displayArgument(char* arr1[],int num)
{
for(int i=0; i<num; i++) {
printf("Argument %d is ",i); //what argument we're on
printf("'%s'\n",arr1[i]);
}
}
//Funtcion to get the length of a command line argument then,
//display number of alphabetical characters it contains
void displayLength(char* arr[],int length)
{
for (int l=0; l<length; l++) { //what length that position is
int len=strlen(arr[l]); //what is the length of position l
printf("Length is %d,\n",len); //print length
for(int j=0; j< len ;j++) {
int atoi(strlen(arr[l][j]));
printf("Contains %d alphabetical characters",arr[l][j]);
}
}
}
//Function to count the total length, concatenate together,
//and display results
//void displayTotalCat(char* arr2[],int total)