|
|
 |
 |
 |
 |
register |
bbs |
search |
rss |
faq |
about
|
 |
 |
meet up |
add to del.icio.us |
digg it
|
 |
 |
| 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. |
 |
|
# 1

2007-04-08, 00:45
|
|
Regular
|
|
yonkers ny
|
|
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.
|
# 2

2007-04-08, 01:08
|
|
|
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'?
|
# 3

2007-04-08, 01:11
|
|
Regular
|
|
yonkers ny
|
|
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?
|
# 4

2007-04-08, 01:16
|
|
|
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/
|
# 5

2007-04-08, 01:21
|
|
|
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.
|
# 6

2007-04-08, 01:23
|
|
Regular
|
|
yonkers ny
|
|
Re: anyone here good with C? quick question
please do. that would be of help
|
# 7

2007-04-08, 01:33
|
|
|
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.
|
# 8

2007-04-08, 03:52
|
|
|
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?
|
# 9

2007-04-08, 05:50
|
|
Regular
|
|
yonkers ny
|
|
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.
|
# 10

2007-04-08, 16:02
|
|
|
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
|
This thread continued for 2 pages in the real archive, 15 posts total - only page 1 survived here.
| Thread Tools |
 Show Printable Version
 Email this Page
|
| Display Modes |
Linear Mode
 Switch to Hybrid 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
HTML code is Off
|
|
|
|
 |
 |
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
|
 |
 |
 |
 |
|
|