LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2004, 11:28 PM   #1
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Rep: Reputation: 0
Question Using *strng vice *(strng + i)


Can someone tell me please why this does not work:
#include <stdio.h>

void display (char []);

int main()
{
char message[] = "Vacation is near";

display (message);

return 0;
}

void display (char*strng)
{
int i = 0++;
while (*strng != '\0', 0++)
{
printf("%c", *strng);
++i;
}
printf("\n");
return;
}

I receive the Errors:
17: Lvalue required in function display(char *)
18: Lvalue required in function display(char *)

Help is much appreciated.
Mike
 
Old 07-23-2004, 11:56 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
A few corrections...

Hi -

Here is the corrected version:
Code:
#include <stdio.h>

void display (char []);

int main()
{
  char message[] = "Vacation is near";

  display (message);

  return 0;
}

void display (char*strng)
{
  while (*strng)
  {
    printf("%c", *strng);
    strng++;
  }
  printf("\n");
}
Here were the problems:

1. You can't increment a literal constant like "0"
<= THIS WAS THE PROBLEM THAT CAUSED THE
TWO COMPILER ERRORS

2. You didn't need an array index, you could just increment the
pointer variable directly (this is the approach I took above).

Here's the same code using an index:
Code:
void display (char*strng)
{
  int i = 0;
  while (strng[i])
  {
    printf("%c", strng[i]);
    i++;
  }
  printf("\n");
}
3. Finally, when posting code on LinuxQuestions.org, be sure to take advantage of the different vbCode tags that are available to you: bold, italic, http ... and, in this case, the "code" tag.

Hope that helps .. PSM

(PS: You'll notice that I *didn't* take advantage of the "list" tag. Or the "italic" tag, either ;-)
 
  


Reply



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
how to use Vice emulator jaakkop Linux - Games 1 03-16-2005 03:45 PM
m1 can ping m2, but not vice versa cmacklin Linux - Networking 4 10-31-2004 08:01 PM
gta vice city in wine drigz Linux - Games 11 07-02-2004 02:11 PM
KDE under Gnome, or vice-versa Pres General 7 02-01-2004 10:18 AM
Can't Eject CD during Vice City install Ehuwiko Linux - Games 2 10-21-2003 07:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration