Run time error?

This is a discussion on Run time error? within the C Programming forums, part of the General Programming Boards category; Dear All, I am getting Run Time Error In Following code, what could be the problem? Code: #include <stdlib.h> #include ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    Run time error?

    Dear All,
    I am getting Run Time Error In Following code, what could be the problem?

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    main ( ) 
    {
    char *str1 = "hS eesll snsiasl not eh es as oher " ;
    char *str2 ;
    swab ( str1, str2, strlen ( str1 ) ) ;
    printf ( "The target string is : %s\n", str2 ) ; // output -- She sells snails on the a shore
    return 0;
    }
    Thanks for Help.

  2. #2
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    You didn't allocate memory for str2. It might be pointing anywhere.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What is swab()? It's not a standard function, and you haven't defined it.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by cpjust View Post
    What is swab()? It's not a standard function, and you haven't defined it.
    swab is a library function declared in the header stdlib.h.its syntax is
    Code:
    void swab(char *from,char *to,int nbytes)
    swab copies nbytes bytes from the "from" string to the "to" string.nbytes should be even.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Looks like it's POSIX, not ISO, but normally found in unistd.h instead of stdlib.h:

    http://en.wikipedia.org/wiki/Swab_(programming)

  6. #6
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    and btw

    str1 should be "hS eesll snsiaslo nht e ahsro e " for your output...
    Code:
    printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Sounds like swab() is a less standard version of the htonl(), htons(), ntohl() & ntohs() functions.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM

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