About
Community
Bad Ideas
Drugs
Ego
Erotica
Fringe
Society
Technology
register | bbs | search | rss | faq | about
meet up | add to del.icio.us | digg it
Go Back   Community > Technology > Technophiliacs & Technophiles
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Technophiliacs & Technophiles The Technophiliacs forum is for discussing any and all forms of tech and other types of social backwardness. Including discussions of strange home-brewed hardware technology. Where to get good tools. How to make fiberglass molds. Computer hardware and software technolgy, including operating systems, applications, networking, hardware, CPU's, disk drives, and other geeky things. Viruses and Artificial Life discussions. How to write HTML. End user tools discussions and support issues. Gating the Internet with other nets. If your computer is better than anyone else's computer, you are required to post a message explaining why. You'll probably be wrong, especially if you're a Mac or BeOS user, but post anyway.

Reply
 
Thread Tools Display Modes
  #1   Add opersono to your ignore list  
Old 2007-04-08, 00:45
opersono opersono is offline
Regular
 
yonkers ny opersono is an unknown
Default anyone here good with C? quick question

okay, so i'm stumped by this question even though I've done java database programming for years, and I know a fair amount of C++.

here is goes. what does this function do in C?


By the way, the two parameters represent char arrays (strings, with a capacity of 80, if that matters).
The user is prompted to input two strings, which are then passed to this function. Here it goes:

Void blah (char *s1, const char *s2)
{

while ( s1 != ‘\10’) /* while it doesn’t equal 10 */
{
s1++;
}


for (; *s1 = *s2; s1++, s2++)
{
; /* YEA, this is an empty statement */

}

} /* end of blah function */

I’ve never heard of incrementing a char array

Please help.
Reply With Quote
  #2   Add jsaxton14 to your ignore list  
Old 2007-04-08, 01:08
jsaxton14 jsaxton14 is offline
Regular
 
Minneapolis, MN, USA Send a message via AIM to jsaxton14 Send a message via MSN to jsaxton14 jsaxton14 is an unknown
Default Re: anyone here good with C? quick question

This is an example of pointer arithmetic. s1 is just a pointer to s1[0]. Incrementing s1 simply increases the address of s1, so it now points to s1[1] instead.

What is '\10'?
Reply With Quote
  #3   Add opersono to your ignore list  
Old 2007-04-08, 01:11
opersono opersono is offline
Regular
 
yonkers ny opersono is an unknown
Default Re: anyone here good with C? quick question

oh shit, i meant \0, as in NULL.

so after this function, what would happen if i were to print the value of s1?
Reply With Quote
  #4   Add jsaxton14 to your ignore list  
Old 2007-04-08, 01:16
jsaxton14 jsaxton14 is offline
Regular
 
Minneapolis, MN, USA Send a message via AIM to jsaxton14 Send a message via MSN to jsaxton14 jsaxton14 is an unknown
Default Re: anyone here good with C? quick question

After a bit of tinkering, I figured out that '\x' is a valid character. x is simply an octal representation of an ascii character. It turns out '\10' is backspace.

http://www.asciitable.com/
Reply With Quote
  #5   Add jsaxton14 to your ignore list  
Old 2007-04-08, 01:21
jsaxton14 jsaxton14 is offline
Regular
 
Minneapolis, MN, USA Send a message via AIM to jsaxton14 Send a message via MSN to jsaxton14 jsaxton14 is an unknown
Default Re: anyone here good with C? quick question

The output of this code is dependent upon the values of *s1 and *s2. If *s1="foo\0barbaz" and *s2="baz", I think what would happen is that a printf("%s\n", s1) would print "rbaz" but I'm not 100% positive.

Let me code up a little test program.
Reply With Quote
  #6   Add opersono to your ignore list  
Old 2007-04-08, 01:23
opersono opersono is offline
Regular
 
yonkers ny opersono is an unknown
Default Re: anyone here good with C? quick question

please do. that would be of help
Reply With Quote
  #7   Add jsaxton14 to your ignore list  
Old 2007-04-08, 01:33
jsaxton14 jsaxton14 is offline
Regular
 
Minneapolis, MN, USA Send a message via AIM to jsaxton14 Send a message via MSN to jsaxton14 jsaxton14 is an unknown
Default Re: anyone here good with C? quick question

I'm an idiot. This is just a version of strcpy(), basically. For some reason I read "*s1 = *s2" as "*s1 == *s2".

For some reason it's not compiling properly on my computer (it keeps segfaulting). I have my own homework to do, so I'm going to start working on that now.

Good luck.
Reply With Quote
  #8   Add carpal to your ignore list  
Old 2007-04-08, 03:52
carpal carpal is offline
Acolyte
 
carpal is an unknown
Default Re: anyone here good with C? quick question

for (; *s1 = *s2; s1++, s2++)
{
; /* YEA, this is an empty statement */

}


I maybe wrong but isn't this an infinite loop?
Reply With Quote
  #9   Add opersono to your ignore list  
Old 2007-04-08, 05:50
opersono opersono is offline
Regular
 
yonkers ny opersono is an unknown
Default Re: anyone here good with C? quick question

i think it just appears that way, but i could just be saying that because the For loops in C could be very different that the For loops in c++ and java.

bump though, i could really use an answer.
Reply With Quote
  #10   Add jsaxton14 to your ignore list  
Old 2007-04-08, 16:02
jsaxton14 jsaxton14 is offline
Regular
 
Minneapolis, MN, USA Send a message via AIM to jsaxton14 Send a message via MSN to jsaxton14 jsaxton14 is an unknown
Default Re: anyone here good with C? quick question

Code:
#include<stdio.h>



int main() {

        int foo[4] = {0,1,2,5};

        int bar[2] = {6,9};

        int i;

        for(i=0;foo[i]=bar[i];i++) {

                printf("%i\n", i);

        }

        return 0;

}
That code results in an infinite loop.

So I was wrong, it turns out that your code just results in an infinite loop. It is not a modified version of strcpy() like I initially thought.

Good luck.

Last edited by jsaxton14 : 2007-04-08 at 16:04. Reason: added code tags
Reply With Quote
This thread continued for 2 pages in the real archive, 15 posts total - only page 1 survived here.
Reply


Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode
Hybrid Mode Switch to Hybrid Mode
Threaded Mode Switch to Threaded Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

 
To the best of our knowledge, the text on this page may be freely reproduced and distributed.
 

totse.com certificate signatures
 
 
About | Community | Bad Ideas | Drugs | Ego | Erotica | Fringe | Society | Technology
Hot Topics