Thread: pointers

  1. #1
    Unregistered
    Guest

    Unhappy pointers

    How can I change this line of code into pointer arithmetic?

    for (k=strlen(t)-1; k>=0; k--)


    And can I use this line in a pointer arithmetic version or do i need to modify it as well?

    sscanf(t,"%s", &line);

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Could you please clarify on what it is you would like to do.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yeah. You definately want to be more specific. What are you trying to use pointer arithmatic for in your example? The only pointer I see there is t, and all you're doing there is finding out how long it is.

    Other than that, you're just counting down...

    Code:
    int w,*x,y,*z;
    char *t = "wheeeeeeeeeeeeeeeeeeee";
    
    for( w=strlen(t),x=&w,y=0,z=&y;(t+*x)!=(t+*z);*x-- )
    Is that enough pointer notation for you?

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >for (k=strlen(t)-1; k>=0; k--)
    This is obviously traversing a string from the end to the front. So it would be something like this:
    Code:
    char *astr = "Some string";
    char *k;
    
    for ( k = &astr[strlen(astr)-1]; k >= astr; k-- )
    >sscanf(t,"%s", &line);
    Be more specific.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM