473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

cstrings

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. void main()
  5. {
  6.     char MyString[]="1.1 You can't have your cake and eat it". 1.2" There's light at the end of the tunnel". 1.3 "Try to complete ALL exercise";
  7.     char ModifiedMyString[]="\0";
  8.     char s1[]="\0";
  9.     char*str1,*str2,*str3,chr;
  10.  
  11.  
  12.     int x=0,j=0,p=0,q=0,m=0,b=0,k=0,l=0,d=0;
  13.     int integer=0;
  14.     int doub=0;
  15.     bool y;
  16.     //(x=strlen(MyString);
  17.     for(int i=0;i<x;i++)
  18.     {
  19.         if (y=isspace(MyString[i]))
  20.             //(y==true)
  21.         {
  22.             if (y=isspace(MyString[i+1]);
  23.  
  24.                     //(y==true)
  25.                     {
  26.  
  27.                     continue;
  28.                     }
  29.  
  30.                     }
  31.  
  32.                     ModifiedMyString[j]=MyString[i];
  33.                     j++;
  34.  
  35.  
  36.                     }
  37.                     cout<<"The string with spaces :"<<MyString<<endl;
  38.                     cout<<"The string without spaces :"<<ModifiedMyString<<endl;
  39.  
  40.                     str1=strtok(MyString," ");
  41.                     while(str1!=NULL)
  42.                     {
  43.  
  44.                         p=strlen(str1);
  45.                         if(p>q)
  46.                         {
  47.                             p=q;
  48.                             str2=str1;
  49.                         }
  50.                         str1=strtok(NULL," ");
  51.                     }
  52.             cout<<"The logngest word is :"<<str3<<endl;
  53.             m=strlen(ModifiedMyString);
  54.             for(int i=0;i<m;i++)
  55.             {
  56.                 chr=ModifiedMyString[i];
  57.                 if(chr=='a')
  58.                 {
  59.                     b++;
  60.  
  61.  
  62.                 }
  63.             }
  64.  
Jan 26 '09 #1
6 2150
Banfa
9,065 Expert Mod 8TB
You have not viewed and checked your post for legibility. If you had you would have seen the mess you have posted. I would be surprised if anyone can be bothered to try an decode what you have posted. I suggest you post again without all the font/size/color tags that are not being interpreted.

As to how it happened I believe that is a reported problem with pasting from Visual Studio into the site advanced editor.
Jan 26 '09 #2
what i paste is different from what i m seeing nw
Jan 26 '09 #3
how can i delete dem
Jan 26 '09 #4
mac11
256 100+
I was bored and felt up to a vim regex challenge so I removed the formatting tags from the original code:

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. void main()
  5. {
  6.     char MyString[]="1.1 You can't have your cake and eat it". 1.2" There's light at the end of the tunnel". 1.3 "Try to complete ALL exercise";
  7.     char ModifiedMyString[]="\0";
  8.     char s1[]="\0";
  9.     char*str1,*str2,*str3,chr;
  10.  
  11.  
  12.     int x=0,j=0,p=0,q=0,m=0,b=0,k=0,l=0,d=0;
  13.     int integer=0;
  14.     int doub=0;
  15.     bool y;
  16.     //(x=strlen(MyString);
  17.     for(int i=0;i<x;i++)
  18.     {
  19.         if (y=isspace(MyString[i]))
  20.             //(y==true)
  21.         {
  22.             if (y=isspace(MyString[i+1]);
  23.  
  24.                     //(y==true)
  25.                     {
  26.  
  27.                     continue;
  28.                     }
  29.  
  30.                     }
  31.  
  32.                     ModifiedMyString[j]=MyString[i];
  33.                     j++;
  34.  
  35.  
  36.                     }
  37.                     cout<<"The string with spaces :"<<MyString<<endl;
  38.                     cout<<"The string without spaces :"<<ModifiedMyString<<endl;
  39.  
  40.                     str1=strtok(MyString," ");
  41.                     while(str1!=NULL)
  42.                     {
  43.  
  44.                         p=strlen(str1);
  45.                         if(p>q)
  46.                         {
  47.                             p=q;
  48.                             str2=str1;
  49.                         }
  50.                         str1=strtok(NULL," ");
  51.                     }
  52.             cout<<"The logngest word is :"<<str3<<endl;
  53.             m=strlen(ModifiedMyString);
  54.             for(int i=0;i<m;i++)
  55.             {
  56.                 chr=ModifiedMyString[i];
  57.                 if(chr=='a')
  58.                 {
  59.                     b++;
  60.  
  61.  
  62.                 }
  63.             }
  64.  
Task 2. find lonest word;(exercise) i try to find this word by i cnt
Task 8. Identify the number of sentences
any one who cn help ,thank you
Jan 26 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
Your are using C++ and therefore should not be using C. Instead yu should be usign C++ string objects.

What you want is a finite state automaton to parse out the words. It would bw trivial to retain the length odf the longest word.

The article below has this coded for you already (except for keeping the longest length).

Read this: http://bytes.com/topic/c/insights/66...patterns-state
Jan 26 '09 #6
Thanx,everyone,who help me.Ur information was helpful.
Can anyone tell me how i cn use strings instead of pointer in that question
Jan 28 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rob Richardson | last post by:
Greetings! I am running into a problem with implicit conversion of arguments when trying to insert the contents of a CString object into a stringstream. I am using the following typedef: ...
0
by: Chris | last post by:
Hi all, Just converted our 95 project workspace file from VC++ 6.0 to .NET, and things have gone...um...pretty well. Down to the last of the suffering - our main server application is doing...
5
by: raz | last post by:
Greetings all. I apologize for what is almost certainly a stupid question, but I can't figure this out, and have no more time for head bashing... The short version: what is the appropriate...
3
by: Bill Hoy | last post by:
Hi, I have a few years of experience using MFC and Microsoft Visual C++ 6.0. As my company gets further into the software business they now want to start moving away from MFC, and use pure...
0
by: Doug Bailey | last post by:
I have an application in which some unmanaged classes are being pulled into a Managed Windows Form application. The umanaged class has a number of CString variables. When I link the program, I...
1
by: JackHWarner | last post by:
I'm porting an app from vc++6 to vc++ 7.1, and am having some trouble exporting functions. I can export simple functions from a DLL by simply putting __declspec(dllexport) in front of them, and I...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
2
by: Sean F. Aitken | last post by:
Good afternoon, We have an app that uses a CMap with CString types for values and accepts LPCSTR as the parameter. The object being created is on the heap (created dynamically). A leak detector...
0
by: coucchy | last post by:
Hello everyone, i'm writing a C program that will read a text file and then encode the characters using huffman algorithm. So far i've read the files, built a tree, and now I'm building the strings...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.