| | |
C++ Question Mark counter-- Any Improvements in Code?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hey all,
I have decided that in order to learn i will need to write code. So i am working on all the questions on my book. And as I am teaching myself i end up with no-one to scrutinize my code.
The above program counts the number of "?" marks in a string passed to it.
I would like to recieve comments on the code
and any improvements that can be made.
I have decided that in order to learn i will need to write code. So i am working on all the questions on my book. And as I am teaching myself i end up with no-one to scrutinize my code.
c++ Syntax (Toggle Plain Text)
#include <iostream> /************Declarations of Functions*********/ void func1(); void func2(); //=============================================Tue 28 Apr 2009 18:37:48 IST// /* Global Test Variables */ int const max_length=18; int quest_count=0 ; char input_line[max_length]="???sky???"; int main() { func1();// Character string with While loop std::cout<<"No Of Question Marks = " << quest_count<< "\n"; quest_count=0; func2();//Pointer Based Passing. std::cout<<"No Of Question Marks(Pointer Based) = " << quest_count<< "\n"; } void func1() { int i=0; while(i<max_length) { if(input_line[i]=='?') quest_count++; i++; } } void func2() { char *ptr=input_line; while(*ptr!=0) { if(*ptr=='?') { quest_count++; } *ptr++; } }
The above program counts the number of "?" marks in a string passed to it.
I would like to recieve comments on the code
and any improvements that can be made. ![]() |
Other Threads in the C++ Forum
- Previous Thread: pointer to TREE structuring
- Next Thread: how to sort Gtk::Treeview?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





