kindly tell what is #pragma warning(disable: 4996) in the above program????and how can we cout the locations of each vowel in the sentence..

..

    #include<iostream>
    #include<cstring>
    using namespace std;
    #pragma warning(disable: 4996)
    int main()
    {
    int vowelcounter = 0;
    char * tokenPtr;
    char myarray [] = "My name is Faraz Saleem Rafai";
    char check [] = "aeiou";
    int length = 0;

    int origlength = strlen(myarray);
    // display all the vowels. Your program doesn't need this part,
    // it's here only to verif the results are right or wrong.

    for (int i = 0; myarray[i] != 0; i++)
    {
    myarray[i] = tolower(myarray[i]);
    if (strchr(check, myarray[i]) )
    cout << myarray[i];
    }

    cout << '\n';
    tokenPtr = strtok(myarray, check);

    while (tokenPtr != NULL)
    {
    length += strlen(tokenPtr);
    tokenPtr = strtok(NULL, check);
    }

    cout << "orig length: " << origlength << " numvowels = " << origlength - length << '\n';
    return 0;
    }

kindly tell what is #pragma warning(disable: 4996) in the above program????and how can we cout the locations of each vowel in the sentence with the above program..

That's a microsoft compiler thing -- it supressed warning number 4996, which is a warning about deprecated functions. Just delete that line if you use another compiler.

how can we cout the locations

What do you mean by "locatins"? The vowel's position within the string? Such as there is an "a" in the 5th position of the string?

and how would u amend the above program for cout the location of each vowel in the sentence?

ya exactly......if there are 3 lines in one string then how will your cout location of each vowel in that string...for example
string1[][]={{My name is Faraz},{Saleem Rafai},{I live in Pakistan}}.
is this intialization right?

You will probably have to use two arrays, one array for the letter and within that an array of each location number. Something like this.

struct location
{
   char letter;
   vector<int> locationNumber;
};

vector<location> locations_array;

The above assumes you have studied std::vector in your class. If not, then maybe you can use linked lists instead of vector.

im talking about finding the location of vowel in that same program made above....dont want to use structures....cant we do this using 2d arrays?

I believe the integer

length

is holding the place of the vowel.
I don't remember exactly how strtok works or what exactly does it
return, but using it you will get the length of the word before the vowel
for all of the vowels by using the while loop.

So isn't your program already finding the vowels?

edit:
I'm not sure what you are trying to accomplish exactly, but strtok should
go through all of the vowels even if the same string has 3 lines.
what exactly are you trying to do? print them in the order they apear?
save them to return to another function?

string can be "blablaiau\n blabla\n test" which is 3 lines
do you want to print:
a-3
a-6
i-7
a-8
u-9
?

ya i want to cout them as per their locations....i.e.a[1][3], i[1][7] , u[1][9] to show that they are found at that particular location
in the string

vowels im getting but i want their locations also
what should i do?
should i declare a 2d array of pointers to vowels for storing their locations with a counter for each vowel or what???

help me out on this one in code form if u can please...ill be grateful.....strtok makes tokens of a sentence with repeated calls

I wouldn't use strtok(), just modify the code previously posted to keep track of the position of each vowel, the loop's i counter is the location within the string. Now all you have to do is add some arrays to save that value.

ok

You should just delete lines 24-34 and do everything within the same loop that begins on line 17. On line 21 you know you've found a vowel and the i loop counter is the position within the string of that vowel. So, all that is left for you to do is save the value of i in an array for the given vowel.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.