Member Avatar for Katara1

hey , if i wanna write this code by " while" loop , what the steps to do that ??

#include<iostream.h> char *TESTmarks(char *t){ char marks [] = {'.',';',':','!',',','?'}; char *newm=new char [strlen(t)]; for( int i = 0;i<strlen(t);i++) { for(int k = 0;k<=7 ;k++) { if(t[i] == marks[k]) t[i] = ' '; } } return t; } main() { char t[50]; cin>>t; cout<<TESTmarks(t); }
Member Avatar for tinstaafl

The while loop will need the same parts that are part of the for loop. Counter, limit,incrementing. In a while loop the limit is included in the statement. The counter is initialized before the statement and the incrementing is done inside the block. As an example:

 //counter int i = 0; //limit while( i<strlen(t)) { for(int k = 0;k<=7 ;k++) { if(t[i] == marks[k]) t[i] = ' '; } //incrementing ++i; } return t; }
commented: THANK YOU !+0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.