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 |
A few corrections...
Hi -
Here is the corrected version: Code:
#include <stdio.h> 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) Hope that helps .. PSM (PS: You'll notice that I *didn't* take advantage of the "list" tag. Or the "italic" tag, either ;-) |
All times are GMT -5. The time now is 06:04 AM. |