strcmp help...

This is a discussion on strcmp help... within the C++ Programming forums, part of the General Programming Boards category; Hi, I've made a program to type out a bunch of text put into the char "sentence". one problem is ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    10

    strcmp help...

    Hi, I've made a program to type out a bunch of text put into the char "sentence". one problem is that the text won't fit to the window. Is there possibly a way to set borderlines for the text? if not then i need some help with strcmp. i have it so it takes the array number, and type it out. and if the array number character is a period, then it makes a new line but i get an error message saying "cannot convert char to const char*" or something.

    Code:
    /****
    Made by James, free for distribution.
    ****/
    
    #include <iostream>
    #include <cstring>
    using namespace std;
    
    int main()
    {
    	char sentence[4000]= "This is a test. It should've made a new line there but it didn't. plz help!";
    	int x;
    	for(x=0; x<=3999; x++)
    	{
                    if(strcmp(sentence[x],".") cout<<"\n";
    		cout<<sentence[x];
    	}
    	cin.get();
    	return(0);
    }
    any ideas?
    ~Wiiplayer12

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    This is probably closer to what you are after:
    Code:
          if ( sentence[x] == '.') cout<<"\n";
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Yes. You are using strcmp() and the first argument you are passing is not a string.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    10
    O, thank you so much dave!
    if anyone wants the working code, here it is:

    Code:
    /****
    Made by James, free for distribution.
    ****/
    
    #include "stdafx.h"
    #include <iostream>
    #include "windows.h"
    #include <cstring>
    using namespace std;
    
    int main()
    {
    	char sentence[4000]= "This is a test.hello.hi.It workS!!!1!.~Wiiplayer12";
    	int x;
    	for(x=0; x<=3999; x++)
    	{
    		cout<<sentence[x];
    		Sleep(50);
    		if(sentence[x]=='.'){
    			cout<<"\n";
    		}	
    	}
    	cin.get();
    	return(0);
    }
    ~Wiiplayer12

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    5,636
    the working code
    Working? Even if it will scan the array outside your string bounds?
    If I have eight hours for cutting wood, I spend six sharpening my axe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fucntion returns -1, Why?
    By Taper in forum C Programming
    Replies: 16
    Last Post: 12-08-2008, 05:30 PM
  2. help with switch statement
    By agentsmith in forum C Programming
    Replies: 11
    Last Post: 08-26-2008, 04:02 PM
  3. problem with strings
    By agentsmith in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 12:07 PM
  4. help with strcmp
    By blork_98 in forum C Programming
    Replies: 8
    Last Post: 02-21-2006, 07:23 PM
  5. strcmp
    By kryonik in forum C Programming
    Replies: 9
    Last Post: 10-11-2005, 11:04 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21