pointer with isspace()

This is a discussion on pointer with isspace() within the C Programming forums, part of the General Programming Boards category; Code: #include <ctype.h> int isspace(int c); if I would use a pointer into isspace function it should be an int ...

  1. #1
    aze
    aze is offline
    Registered User
    Join Date
    Sep 2003
    Posts
    18

    pointer with isspace()

    Code:
    #include <ctype.h>
    
    int isspace(int c);
    if I would use a pointer into isspace function it should be an int or char pointer?
    Code:
    if (isspace(*mypointer))
    ...

  2. #2
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    why not try yourself?

    it should be int, however if you use char the program will work, but the compiler will give you a warning:
    Code:
    assignment from incompatible pointer type

  3. #3
    aze
    aze is offline
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    thanks

  4. #4
    aze
    aze is offline
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    void main()
    {
    	char *p;
    	char k[] = "your string here";
    	p=&k;
    	while(!isspace(*p++));
    	printf("%s",p);
    	
    }
    OUTPUT: string here

    I cant understand it.

    printf("%s",p);
    shouldnt be printf("%s",*p); ?

    char *p;
    shouldnt be int *p; ?

    so, if change it BCC55 says:
    Code:
     Error E2342 teste.c 9: Type mismatch in parameter '__s' (wanted 'const signed char *', got 'int') in function main

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    void main()
    Should be
    Code:
    int main(void);
    p=&k;
    should be
    Code:
    p = k;
    or
    Code:
    p = &k[0];
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    int main(void)
    {
      char *p;
      char k[] = "your string here";
      p=k;
      while(!isspace(*p++));
      printf("%s",p);
      return 0;
    }
    Will output
    string here

  6. #6
    aze
    aze is offline
    Registered User
    Join Date
    Sep 2003
    Posts
    18
    char *p;
    shouldnt be int *p; ?

    if the pointer is int it do not point to the string

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    it SHOULD NOT be an int pointer doing so will printout every 4th character. However if you are getting warnings/errors from the isspace() call then you can use:
    Code:
    while(!isspace((int)*p++));
    Which will cast the character to an int.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-24-2008, 11:16 AM
  2. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 08:12 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  4. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 08:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21