Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

lets say that we have: string list[]= {"12.34.56.78","55.34.5","23.44.5"} I want the user to enter part of the string which is also a string: for example string 55 and it will loop through the string a and look for the whole string and print "55.34.5" What I was doing is: str is a string input and list is a whole list of the strings for (int i=0; i

OpenStudy (bahrom7893):

wel your string was called a, not list.. or was it called a list?

OpenStudy (anonymous):

its called list

OpenStudy (anonymous):

You want to be able to search for strings by a prefix, correct? So, for each string, you want to check if the first characters are the same. This should require only 2 loops. for (int i=0; i<n; i++){ for (int j=0; j<str.length()&&j<list[i].length(); j++){ if (list[i][j] == str[j]) cout<<list[i]<<endl; else break;

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!