command line

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
#include <iostream>
#include <fstream>
using namespace std;

void lettercount();
int main(int letter,char *letter[],){


 while (letter[1])
   {
     lettercount();
   }


 return 0;
}
void lettercount()
{
  int total=0;
  for (int i=0;i<letter[1];i++)
    {
      total=total+i;
    }

  cout<<"count of " <<letter[1]<<total<<endl;
}

input
this is just an example of many A aa Aa
./pgm a <datafile
output
count of a: 6
what is wrong with my code
almost , all of your code is wrong !!
first what is your mean about :
while ( letter[1] ) ...
leter[1] return char * to first block of array at index of 1 .
secondly
how to use letter in lettercount function ?!!! letter is one of local variable of main function not lettercount !!!
third what is ',' after letter at the main ?
Fourth if letter[1] exist while ( letter[1] ) be infinit loop !!
Fifth i < letter[1] is wrong of course in your algorithm which letter is char *letter[] !! of course we dont have this type in lettercount function i say this entirely!
Last edited on
and another thing :
you cant send all of "this is just an example of many A aa Aa" into just letter[1] !!! each of word insert into one of index of argv
Topic archived. No new replies allowed.