473,486 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to remove one character on a string? HELP!

3 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<string.h>
  5.  
  6. void main()
  7. {
  8. clrscr();
  9.  
  10.     char first[10], second[10];
  11.     int ctr,ctr2,ctr3,len1,len2,word=0,count=0,larger=0;
  12.     int tae1,tae2;
  13.  
  14.     cout<<"Enter the first word:";
  15.     scanf("%s",&first);
  16.     cout<<"Enter the second word:";
  17.     scanf("%s",&second);
  18.  
  19.     len1 = strlen(first);
  20.     len2 = strlen(second);
  21.  
  22.     tae1=len1-1;
  23.     tae2=len2-1;
  24.  
  25.     for(ctr=0;ctr==tae1;ctr++)
  26.     {
  27.     for(ctr2=0;ctr2==tae2;ctr2++)
  28.     {
  29.         if(strcmp(&first[ctr],&second[ctr2]));
  30.         {
  31.           second[ctr2]='\0';
  32.           word++;
  33.         }
  34.     }
  35.     if(word>=2)
  36.     {
  37.         for(ctr3=0;ctr3==tae1;ctr3++)
  38.         {
  39.             if(!strcmp(&first[ctr],&first[ctr3]))
  40.             {
  41.             larger++;
  42.             }
  43.         }
  44.         if(word>larger)
  45.         {
  46.            cout<<"The first word is NOT";
  47.            break;
  48.         }
  49.         else if(word<=larger)
  50.         {
  51.            word=0;
  52.            count++;
  53.         }
  54.     }
  55.     if(word==1)
  56.     {
  57.         word=0;
  58.         count++;
  59.     }
  60.   }
  61.  
  62. if (count==tae2)
  63. {
  64.     cout<<"The second word is anagram of the first word";
  65. }
  66.  
  67. else
  68.     {
  69.     cout<<"The second word is not an anagram of the first word";
  70.     }
  71. cout<<word;
  72. cout<<second[1];
  73. getch();
  74. }
we can't make the strcmp work :(
how do we make it work?
Jun 27 '10 #1
5 2577
weaknessforcats
9,208 Recognized Expert Moderator Expert
strcmp returns flase if the strings are equal:

Expand|Select|Wrap|Line Numbers
  1. if (!strcmp(&first[ctr],&second[ctr]))
  2. {
  3.    /* first and second are equal from ctr to the end */
  4.    /* of the the string */
  5. }
strcmp returns 0 (false) if the strings are equal.
strcmp returns a value <0 if first is less than second
strcmp returns a value >0 if first is greater than second.

Use strncmp to compare n characters starting at the address specified in the arguments.
Jun 27 '10 #2
mamabear
3 New Member
@weaknessforcats
the strings are not suppose to be equal, it's intended to be if(!strcmp(&first[ctr],&second[ctr2])), and how can we know if it's less than or equal, we're using char, not int.. we need to make the strcmp run so that it can read the if statements.
Jun 27 '10 #3
mamabear
3 New Member
oh the problem is: create a program that will allow the user to input two words and determine if the second word is an anagram of the first word. example: first word is program, the second word is gram. the output should be, the second word is an anagram of the first word. but if i put ggram as a second word, the output should be, the second word is not an anagram of the first word. get it?
Jun 27 '10 #4
whodgson
542 Contributor
The loop conditions at lines 25 and 27 don`t seem right.
What would be the required response if the second word was 'ram'?...in other words what is the definition of anagram being used?
Jun 28 '10 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
The way you have this det up, first and second are strings that have one word only.

A string is a char array where the last element is a binary 0. A char is an integer.

To compare two characters you use:

Expand|Select|Wrap|Line Numbers
  1. if (first[ctr] == second[ctr2]) etc...
  2. if (first[ctr] < second[ctr2]) etc...
  3. if (first[ctr] > second[ctr2]) etc...
Remember, a char is an integer. The compiler will promote the char to an int and do the comare as for int.

You use strcmp to compare entire strings.

The post says to remove a single character from a string.
I would use strcat to append characters to a new string skipping the one I want to remove. But this does not involve strcmp and a lot of complicated code. So I guess I'm not sure what you want to do.
Jun 28 '10 #6

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

Similar topics

0
2156
by: MLH | last post by:
Is an apostrophe a character of special significance to MySQL in a way that would cause "Bob's dog" to become translated into a 12-character string when typed into a MySQL memo field? If I type...
4
17813
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
2
9275
by: Roy Rodsson via .NET 247 | last post by:
Hi all! I am using a stored procedure in SQL2000 for retrieving fileinformations from a db. the table as an uniqueidentifier for the file information. The stored procedure has a variable...
7
2494
by: Justin | last post by:
i need to build the unsigned character string: "PR0N\0Spam\0G1RLS\0Other\0Items\0\0\0" from the signed character string: "PR0N Spam G1RLS Other Items" Tokeninzing the character string is not...
5
4836
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** ...
5
9196
by: Paul Aspinall | last post by:
Hi I want to send an ASCII character string / stream to an IP address. I basically have 6 barcode printers, and a web interface. Depending on what is entered on the web page, will determine...
25
6502
by: lovecreatesbeauty | last post by:
Hello experts, I write a function named palindrome to determine if a character string is palindromic, and test it with some example strings. Is it suitable to add it to a company/project library...
8
11845
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
2
26700
by: pbmanikandan | last post by:
Horrible error. I use a function called cleanse company name that "removes" some strings if present from a string that is passed to it. In a procedure, I do the following. INSERT into table1...
3
3055
by: Gmuchan | last post by:
Hi, Help needed please. Basically I am wanting to update a 16 digit character string which is in a table called say accounts. If the account no. field is say 0502562389568745 I want to...
0
7173
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...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.