Results 1 to 2 of 2

Thread: pointers

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    5

    pointers

    can anyone see what is wrong with this code?

    When I try to type a text with spaces and I expect the program to replace each space with three stars it does not do that?
    the code is as Follows:-

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char *s,ch;
    int i=0,j=0;
    printf("Please input a line with text and spaces?\n");
    do
    {
    ch=getchar();
    s[i]=ch;
    i++;
    }
    while(ch!='\n');


    //**************
    do
    {
    ch=s[j];
    j++;
    if( ch == 32)
    printf("***");
    else
    printf("%c",ch);
    }
    while(ch!='\n');

    getch();

    }

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    try changing

    char *s,ch;

    to

    char s[225],ch;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width