LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-31-2008, 10:40 AM   #1
macdan74
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Rep: Reputation: 0
Question Using pointers in Eclipse 3.3.2 on SuSE 10.3 platform


Hi people,

I'm fairly new to the Linux world, building my own at least, I decided on it to help me develop my C programming skills as well as my Linux understanding.

I have a fairly stable version of SuSE 10.3 running and am using Eclipse 3.3.2 as my IDE.

I've been building basic C programs out of K&R up to Chapter 4 successfully... though I did struggle a bit learning how to get math.h included in a build, linking -lm, easy when you know how... but suffice to say, programming with C using Eclipse on SuSE 10.3 is working so far.

I am really stuck with pointers now though, as an example I'll show you a simplified version of strcpy that I can't get working.

-Headers included are: stdio.h; stdlib.h; (and even) stdint.h;

-The calling function initialises the pointers and calls strcpy as follows:

...
1. char *a = "world!";
2. char *b;
3. strcpy(a,b);
4. ...

5. void strcpy(char *t, char *s)
6. {
7. while((*s = *t) != '\0') {
8. t++;
9. s++;
10. }
11. }


I broke strcpy down this far to see if I could get any further whilst debugging, but it still crashes/terminates on the while statement, line 7. As I single step through the code it steps on line 7 twice then crashes every time.

I was able to get the same code working in a Windows IDE, and I hope my programming isn't that bad that I can't see something really simple wrong with this code.

My guess is that I need to set something up in Eclipse, similar to what I did for using math.h previously?

Or possibly there are constraint on the gcc compiler on how pointers are used?

I have tried to find my way around Eclipse help pages and website to search out the answer but have been unsuccessfully so far.

Any advice will be gladly received.

Thanks!

ps
Seeing as this is my first post I should add - I find Linux a much more involved OS than Windows, but you get a real feel for what you're doing... I like it :-)
 
Old 05-31-2008, 11:00 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,783

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
Code:
 while((*s = *t) != '\0') {
If I read this correctly, (*s = *t) is an assignment, and != is negative equality. Try
Code:
 while((*s == *t) != '\0') {
 
Old 05-31-2008, 12:00 PM   #3
macdan74
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Using pointers in Eclipse 3.3.2 on SuSE 10.3 platform

Quote:
Originally Posted by bigrigdriver View Post
Code:
 while((*s = *t) != '\0') {
If I read this correctly, (*s = *t) is an assignment, and != is negative equality. Try
Code:
 while((*s == *t) != '\0') {
I should of mentioned in my post, strcpy is meant to copy string t to string s rather than compare it.

Thanks for the reply :-)
 
Old 05-31-2008, 05:04 PM   #4
macdan74
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Red face

Quote:
Originally Posted by macdan74 View Post
I should of mentioned in my post, strcpy is meant to copy string t to string s rather than compare it.

Thanks for the reply :-)
Here is a proper version of strcpy, and the same problem still exists.

char strcpy(char *t, char *s)
{
char* r = t;
while ((*t++ = *s++) != '\0')
;
return r;
}

I really think the problem is in my project properties, I must be missing something really simple for a function like this not execute properly...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Next Eclipse platform in two years LXer Syndicated Linux News 0 03-20-2008 10:50 AM
LXer: Get started with the Eclipse Platform LXer Syndicated Linux News 0 07-24-2007 03:16 AM
LXer: Debugging with the Eclipse Platform LXer Syndicated Linux News 0 05-04-2007 10:16 AM
LXer: Eclipse: Empowering the universal platform LXer Syndicated Linux News 0 04-04-2007 07:46 AM
Eclipse Platform is slow sparckis Linux - Newbie 1 02-10-2007 01:29 AM


All times are GMT -5. The time now is 04:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration