A
arnuld
i am not able to figure out the error:
/* C++ Primer - 4/e
*
* exercise 7.16
* STATEMENT:
* write a programme that accepts the arguments to main. print
* the values passed to main.
*
*/
#include <iostream>
int main( int argc, char **argv )
{
std::cout << "These arguments were passed to 'main()' :\t";
/* an int vale can be printed easily */
std::cout << argc << "\t";
/* to prinit array of strings, we need to consider 2 pointers:
one to the 1st character in string literal presented in the array and 2nd
to the 1st element of the array itself.
to print the string literals we will use pointer to a pointer to char
and to move around in the array we will use a pointer to char.
*/
char *pchar = 0;
pchar **p_string = **argv;
char *p_index = *argv;
while( *p_string++ != '\0' )
{
while( **p_index != '\0' )
{
std::cout << **p_index++;
}
std::cout << "\t";
}
return 0;
}
/* OUTPUT
~/programming/cpp $ g++ -ansi -pedantic -Wall -Wextra ex_07-16.cpp
ex_07-16.cpp: In function 'int main(int, char**)':
ex_07-16.cpp:28: error: 'p_string' was not declared in this scope
ex_07-16.cpp:33: error: invalid type argument of 'unary *'
ex_07-16.cpp:35: error: invalid type argument of 'unary *'
~/programming/cpp $
*/
/* C++ Primer - 4/e
*
* exercise 7.16
* STATEMENT:
* write a programme that accepts the arguments to main. print
* the values passed to main.
*
*/
#include <iostream>
int main( int argc, char **argv )
{
std::cout << "These arguments were passed to 'main()' :\t";
/* an int vale can be printed easily */
std::cout << argc << "\t";
/* to prinit array of strings, we need to consider 2 pointers:
one to the 1st character in string literal presented in the array and 2nd
to the 1st element of the array itself.
to print the string literals we will use pointer to a pointer to char
and to move around in the array we will use a pointer to char.
*/
char *pchar = 0;
pchar **p_string = **argv;
char *p_index = *argv;
while( *p_string++ != '\0' )
{
while( **p_index != '\0' )
{
std::cout << **p_index++;
}
std::cout << "\t";
}
return 0;
}
/* OUTPUT
~/programming/cpp $ g++ -ansi -pedantic -Wall -Wextra ex_07-16.cpp
ex_07-16.cpp: In function 'int main(int, char**)':
ex_07-16.cpp:28: error: 'p_string' was not declared in this scope
ex_07-16.cpp:33: error: invalid type argument of 'unary *'
ex_07-16.cpp:35: error: invalid type argument of 'unary *'
~/programming/cpp $
*/