Replacing Characters

This is a discussion on Replacing Characters within the C Programming forums, part of the General Programming Boards category; How am I doing this wrong. It seems to be replacing my whole string with either \' or spaces. Code: ...

  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398

    Replacing Characters

    How am I doing this wrong. It seems to be replacing my whole string with either \' or spaces.
    Code:
    	for (i = 0; i < sizeof(id3v1.artist); i++)
    	{
    		if (strcmp(id3v1.artist + i, "\"") == TRUE)
    		{
    			memcpy(id3v1.artist + i, "\'", sizeof(char));
    		}
    	}
    My struct looks like this
    Code:
    struct id3v1
    {
    	char title[30];
    	char artist[30];
    	char album[30];
    	char year[4];
    	char comment[30];
    	BYTE genre;
    }	id3v1;

  2. #2
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    memcpy(id3v1.artist + i, "\'", sizeof(char));
    should be:

    memcpy(id3v1.artist + i, "\"", sizeof(char));

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    strcmp does not returns TRUE or FALSE

    strcmp used to compare strings not chars

    Code:
    if (id3v1.artist[i] == '\"')
    {
    	id3v1.artist[i] = '\'';
    }
    something like that should work better for replacing 1 char
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > for (i = 0; i < sizeof(id3v1.artist); i++)
    In addition to the other comments, strlen() might be more appropriate here:
    Code:
    	size_t len = strlen(id3v1.artist);
    	for (i = 0; i < len; i++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  3. How do you check how many characters a user has entered?
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 07:05 AM
  4. Replacing characters
    By Beowolf in forum C++ Programming
    Replies: 8
    Last Post: 11-13-2007, 06:17 PM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM

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