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
wel your string was called a, not list.. or was it called a list?
its called list
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;
Join our real-time social learning platform and learn together with your friends!