Thread: Replacing Characters

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

    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 10:39 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03: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, 06: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, 04:54 PM