Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Noobish C Fail - 'Permission Denied' - recreating Soundex code

Started 1 month, 2 weeks ago by peteruk
Hey guys, The lastest episode in the saga of my wrestle to get to grips with C revolves around my inability to handle arrays. I've been tasked with recreating the Soundex code. This involves several stages - removing vowels from a set of characters, removing double letters, and then translating it into a numeric code. However, that all sounds pretty daunting, so to get to grips...
Site: Overclockers UK Forums  Overclockers UK Forums - site profile
Forum: HTML, Graphics & Programming  HTML, Graphics & Programming - forum profile
Total authors: 6 authors
Total thread posts: 18 posts
Thread activity: no new posts during last week
Domain info for: overclockers.co.uk

Other posts in this thread:

dave-lew99 replied 1 month, 2 weeks ago
For a start you can't call Code: a[26] ='\0'; when you intialised the array with Code: char a[26]; As you are accessing the 27th element (it's numbered from 0-25) So you'll be getting memory corruption issues right there. Same with Code: for (i=0,i<=20,i++) You're trying to access the 21st element. And surely you don't want Code:...

peteruk replied 1 month, 2 weeks ago
Dave, Thanks for pointing out my newbish mistakes! And taking the time to explain why they are so. I've modified the length of a [] to 27 characters (I didn't understand before that was how they were numberd) to prevent that fault. I've done a similar thing with the i variable by reducing the continuation parameter to i<=19. I've also changed the scanf and printf to reflect the correct...

animatronic replied 1 month, 2 weeks ago
Have a look at strpbrk

Caustic replied 1 month, 2 weeks ago
Firstly, please use the Code: code tag for code as it preserves the tabbing! The first problem I can see is you are doing: if (B[i]=a[0]) You want the comparason operator '==' not '=', the asignment operator. But then you are assigning B[i]=0; This will not remove the vowel, but terminate the string. So "test" will change to "t\0st" which is "t". You are also ...

BullBoyShoes replied 1 month, 2 weeks ago
you cant initialise an array like that. do this as an example instead char a[5] = "ABCDE"; or char a[5] = {'A','B','C','D','E'); also using single letters as variable names is not recommended and a practice I would advise you to get out of! Is 'devowel' a function? It may just be the formatting of the text but if it is then the syntax is all wrong

Caustic replied 1 month, 2 weeks ago
You can initialise an array that way, it far from great, but it works. I guess technically you are not initialising the array at all and leaving it up to the whims of the compiler but setting all the values very soon after. However, my next suggestion was going to be to rework how that array work completely and it isn't the ops biggest issue I was curious as to what is going on with the ...

BullBoyShoes replied 1 month, 2 weeks ago
my point is, there is a declaration (char a[]) some code and then another declaration (char b[]) - this is not allowed in C and likely to be one of the causes of the errors

peteruk replied 1 month, 2 weeks ago
Hey everyone, I've taken in your comments and spent some more time researching. I've made a few changes and updated my op with the correct coding. I understand however there are a few fundamental flaws with the way I'm coding, but for now that's how I understand it. Quote: You want the comparason operator '==' not '=', the asignment operator. But then you are ...

Caustic replied 1 month, 2 weeks ago
Quote: Originally Posted by BullBoyShoes my point is, there is a declaration (char a[]) some code and then another declaration (char b[]) - this is not allowed in C and likely to be one of the causes of the errors Declaration of char b[] is commented out. UPDATE2: I missed one thing you changed. I see B is ...

BullBoyShoes replied 1 month, 2 weeks ago
devowel asks for a char *, so you need to dereference the pointer when you call the function like this: devowel(&B);

 

Top contributing authors

Name
Posts
peteruk
6
user's latest post:
Noobish C Fail -...
Published (2009-11-10 14:30:00)
Quote: Originally Posted by Caustic Okay, so yes, that does make sense. Cool. Does that mean my shift function still needs changing though?
Caustic
6
user's latest post:
Noobish C Fail -...
Published (2009-11-10 15:08:00)
Quote: Originally Posted by peteruk Does that mean my shift function still needs changing though? Yes, you must make sure that all array indexing stays inside its bounds. C does no checks to detect (or stop) this and array out-of-bounds problems will cause major headaches later. EDIT: However, there is always an exception to the rules. Strings in C are null terminated. So the string &quot;test&quot; is stored using 5 bytes,...
BullBoyShoes
3
user's latest post:
Noobish C Fail -...
Published (2009-11-09 23:08:00)
devowel asks for a char *, so you need to dereference the pointer when you call the function like this: devowel(&amp;B);
dave-lew99
1
user's latest post:
Noobish C Fail -...
Published (2009-11-08 23:40:00)
For a start you can't call Code: a[26] ='\0'; when you intialised the array with Code: char a[26]; As you are accessing the 27th element (it's numbered from 0-25) So you'll be getting memory corruption issues right there. Same with Code: for (i=0,i&lt;=20,i++) You're trying to access the 21st element. And surely you don't want Code: scanf (&quot;%f&quot;,B); As thats reading in floats? Surely you...
animatronic
1
user's latest post:
Noobish C Fail -...
Published (2009-11-09 10:10:00)
Have a look at strpbrk
_TubbZ_
1
user's latest post:
Noobish C Fail -...
Published (2009-11-11 23:21:00)
You could use a While loop which stops when the character is null then you will not need to do the count and will notoverflow the inputted string. Code: int something( char * s ) { while( *s++ ) { //do your business } return //an int } But as thats a bit of a pain to read you can always just do the strlen inside the function rather than having to pass it in and make it a bit nicer to use.

Related threads on "Overclockers UK Forums":

Related threads on other sites:

Thread profile page for "Noobish C Fail - 'Permission Denied' - recreating Soundex code" on http://www.overclockers.co.uk. This report page is a snippet summary view from a single thread "Noobish C Fail - 'Permission Denied' - recreating Soundex code", located on the Message Board at http://www.overclockers.co.uk. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity