+ 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

10th Dec 2019, 5:41 PM
Zohal
Zohal - avatar
19 odpowiedzi
+ 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
11th Dec 2019, 9:20 AM
Zohal
Zohal - avatar
+ 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.
10th Dec 2019, 6:23 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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.
10th Dec 2019, 5:50 PM
Deroman
Deroman - avatar
+ 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.
10th Dec 2019, 6:00 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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 } }
10th Dec 2019, 6:06 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
So you need to keep iterating in an array, until it doesn't encounter any upper case letter?
10th Dec 2019, 6:12 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
Zohal could you show the complete code that you have tried? rodwynnejones Most probably yes, that's what he is wanting.
11th Dec 2019, 2:57 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
Yup, definitely true.
11th Dec 2019, 3:40 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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; } } }
11th Dec 2019, 9:25 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Poda dai poda vera velai iruntha paaruda
12th Dec 2019, 4:42 AM
Dhanush
0
Im writing a longer code this is a part of it, its supposed to take for example "zohalGhasemzadeh" and give "Ghasemzadeh"
10th Dec 2019, 5:52 PM
Zohal
Zohal - avatar
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
10th Dec 2019, 6:02 PM
Zohal
Zohal - avatar
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
10th Dec 2019, 6:10 PM
Zohal
Zohal - avatar
0
Yes, unless its impossible, then I have to find another way of writing this
10th Dec 2019, 6:13 PM
Zohal
Zohal - avatar
0
Its wierd but it gives no output
10th Dec 2019, 6:43 PM
Zohal
Zohal - avatar
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"?
10th Dec 2019, 8:52 PM
rodwynnejones
rodwynnejones - avatar
0
هلو
11th Dec 2019, 3:59 AM
عاشقة الهدوء
0
سلام ایرانی هستی؟
12th Dec 2019, 8:40 AM
Arya Aviny
0
ارور اینه که با دوتا حلقه هنوز نتونستی دونفرو بهم برسونی 😂🤣
16th Dec 2019, 10:31 PM
Milad m18
Milad m18 - avatar