Error | Sololearn: Learn to code for FREE!

+1

Error

#include <iostream> #include <string> using namespace std; int main() { string name [100]; int i,j; for (i = 0 ;name [i]!= "\n" ; i++) { for (j=0 ; name [i][j] > 90 ; j++) cin >> name [i][j]; } cout << name [0]; system ("pause"); } I gave this code "zohalGhasemzadeh" and it gives me this error Unhandled exception, access violation reading location I dont know what to do

12/10/2019 5:41:19 PM

Zohal

20 Answers

New Answer

+2

nAutAxH AhmAd I asked my TA he told me cin cannot get "\n" so the loop goes on even till name [200] which we dont have so its wrong

+3

for (int i = 0; i < 100; i++) { bool isFound = false; for (int j = 0; name[i][j] != '\0'; j++) { if(name[i][j] >= 65 && name[i][j] < 92) { isFound = true; } if(isFound) cout << name[i][j]; } cout << "\n"; } This should work as you are expecting. It will print every character of each string after first upper case letter is found from each string. For inputting the array, you need to write the same code as told above.

+2

Next time you comment a code, insert it from the code playground so it's easier to read, try and fix. Also, please try to explain what are you trying to achieve; I don't understand your thinking behind the code.

+2

Your loops and their conditions are not correct. First of all, to take input for string array: string name[100]; for(int i = 0; i < 100; i++) { cin >> name[i]; } Above code is used to take input for string type arrays.

+2

For that you need to write like this: for (int i = 0; i < 100; i++) { for (int j = 0; name[i][j] != '\0'; j++) { // Do your stuff } }

+2

So you need to keep iterating in an array, until it doesn't encounter any upper case letter?

+1

Zohal could you show the complete code that you have tried? rodwynnejones Most probably yes, that's what he is wanting.

+1

Yup, definitely true.

+1

#include <iostream> #include <string> #include <cctype> using namespace std; int main(){ unsigned int size = 5; // << change this value to suit your needs. string names[size]; string name; // #### This section is the input (string,...no spaces)#### for(unsigned int i = 0; i < size; i++){ cin >> name; names[i] = name; } // #### This section is the output. #### for(string str: names){ for(unsigned int x = 0; x < str.length(); x++) if(isupper(str[x])){ cout << str.substr(x) << endl; break; } } }

+1

Poda dai poda vera velai iruntha paaruda

0

Im writing a longer code this is a part of it, its supposed to take for example "zohalGhasemzadeh" and give "Ghasemzadeh"

0

I wanted the code to check every character of the string so I wrote it like this, please tell me the right code if this is wrong

0

Well I still gotta write cin >> name [i] [j] in the end it will be the same, except that I want it to type until there is a capital letter, and I dont know how many strings Im supposed to take thats why I cant put i < 100 cause it will cin exactly 100 arrays

0

Yes, unless its impossible, then I have to find another way of writing this

0

Its wierd but it gives no output

0

Before I post what I've done..I need to double check what your looking to... You want to input upto 100 strings (names)... and for each name...you want to check for an uppercase character... ..and if it has... you what to cout the name like your example "zohalGhasemzadeh" and give "Ghasemzadeh"?

0

0

سلام ایرانی هستی؟

0

ارور اینه که با دوتا حلقه هنوز نتونستی دونفرو بهم برسونی 😂🤣

-2

Perdana gays