![]() |
| | #1 |
| Registered User Join Date: Mar 2008
Posts: 39
| Code: int main(void)
{
char *a = "Hello, World!";
printf("%s\n",&a[1]);
return 0;
}
|
| thungmail is offline | |
| | #2 |
| Registered User Join Date: Oct 2009 Location: While(1)
Posts: 316
| Because you printging the string which will start from base address + 1 in your case a + 1 if you will change you code to Code: printf("%c\n",a[0]);
|
| RockyMarrone is offline | |
| | #3 |
| Registered User Join Date: Mar 2008
Posts: 39
| thanks for your help but i still feel confused if i use Code: printf("%s\n",&a[1]);
Code: ello, World! |
| thungmail is offline | |
| | #4 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #5 | |
| Registered User Join Date: Mar 2008
Posts: 39
| Thanks for all your answers. For the problem above, according to laserlight Quote:
Code: printf("%s\n",*a[1]);
This error still occurs when I try an example above. If I have Code: char * str if i have Code: 1.for(;*(str+i) != '\0';i++)
2.{
3. if(isupper(str[i])) // Check if every char in str is capital
4. do something
5.}
Code: isupper(*(str[i])) Code: invalid type argument of `unary *' Last edited by thungmail; 11-05-2009 at 02:47 AM. | |
| thungmail is offline | |
| | #6 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #7 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| The index operator dereferences the pointer, so in effect a[1] is the same as *(a + 1), so no * is necessary.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #8 |
| Registered User Join Date: Mar 2008
Posts: 39
| Thanks a lot it is clear now There is another question I want to ask about the fgets() in C. Here is my code Code: #include <string.h>
#include <stdio.h>
1.int main (int argc, char *argv[]){
2. char* input;
3. char* arg;
4. fgets ( input ,43, stdin ) ;
5. arg = strtok(input," ");
6. printf("%s\n",arg);
7.}
Code: red 313 % input.out input from the screen Segmentation fault Code: input from the screen |
| thungmail is offline | |
| | #9 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
|
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| newbie needs help with code | compudude86 | C Programming | 6 | 07-23-2006 08:54 PM |
| How to fix misaligned assignment statements in the source code? | biggyK | C++ Programming | 28 | 07-16-2006 11:35 PM |
| Personal Program that is making me go wtf? | Submeg | C Programming | 20 | 06-27-2006 12:13 AM |
| Please Help - Problem with Compilers | toonlover | C++ Programming | 5 | 07-23-2005 10:03 AM |
| linked list inside array of structs- Syntax question | rasmith1955 | C Programming | 14 | 02-28-2005 05:16 PM |