Help needed with array comparisons.. Newbie to C

need help to remove repeated characters in a string

Page 1 of 1

3 Replies - 1025 Views - Last Post: 29 November 2007 - 09:54 AM Rate Topic: -----

#1 rustix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-November 07

Help needed with array comparisons.. Newbie to C

Post icon  Posted 28 November 2007 - 11:00 AM

How could I create a function to check whether a string (word or sentence) passed into an array have any repeating character and delete them?

This is what I've done so far:

#include <stdio.h>

/*
1) Enter in a string
2)String should be checked for repeating characters (call a function)
3)The repeating characters hould be deleted (within the function)
4)New modified string should be displayed (returned from the function to be printed in the main method)
*/

//check whether repeating strings are present
char no_repetitions(char str[]);

char no_repetitions(char str[])
{
	
}

//main method
main()
{
	static char string[] = "this is";
	printf ("Enter in a string : ");
	scanf ("%s", string);
	printf ("The entered words in : %s", string);
}



example of expected output

Quote

Enter a string : This string contains repeated characters
The string without repetition is : This trngcoaepd


I know it's not much at all but I really am a newbie and want to know could this be done? are regular expressions involved? is there a way to do this with out using reg expressions?

This post has been edited by rustix: 28 November 2007 - 11:31 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help needed with array comparisons.. Newbie to C

#2 Pontus  Icon User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Re: Help needed with array comparisons.. Newbie to C

Posted 28 November 2007 - 02:50 PM

gonna give u some pseudocode
create another array that will hold all the chars already found (array2)
start looping to all characters
if the current char is already in array2 delete it
else
add it to array2
end loop


now the code for the removal in an array
char *delete(char *inputarray,int wich,int sizeofarray)
{
 int b=0;
 char ret[sizeofarray-1];

 for(int a=0;a<sizeofarray-1;a++)
 {
  if(a!=wich)
  ret[a]=inputarray[b++];
 }
}


Was This Post Helpful? 0
  • +
  • -

#3 rustix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-November 07

Re: Help needed with array comparisons.. Newbie to C

Posted 28 November 2007 - 09:48 PM

View Postmanhaeve5, on 28 Nov, 2007 - 02:50 PM, said:

now the code for the removal in an array
char *delete(char *inputarray,int wich,int sizeofarray)
{
 int b=0;
 char ret[sizeofarray-1];

 for(int a=0;a<sizeofarray-1;a++)
 {
  if(a!=wich)
  ret[a]=inputarray[b++];
 }
}



thanks i managed to do it but without the removal in an array part... i don't quite understand why you have that part..
Was This Post Helpful? 0
  • +
  • -

#4 Pontus  Icon User is offline

  • Cattlebruiser

Reputation: 18
  • View blog
  • Posts: 612
  • Joined: 28-December 06

Re: Help needed with array comparisons.. Newbie to C

Posted 29 November 2007 - 09:54 AM

To remove characters in an array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1