Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please I need help about C program 2

Status
Not open for further replies.

sillyonion

Technical User
Apr 6, 2000
1
US
/*The question is a function deblank that takes a string output and a string input argument and returns a copy of the input argument with all blanks removed.<br><br>I did this program, but does not work.&nbsp;&nbsp;Could some body can correct my program?&nbsp;&nbsp;I will very appreciate!!!<br>Sophia*/<br><br>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;<br><br><br>int<br>main(void)<br>{<br> char string[81]; <br> char blank[81] =
 
Hi,<br>&nbsp;I've included 3 files just read the content , it removes all the white space from a string.<br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br><br>#include &lt;ctype.h&gt;<br>#include &quot;snip_str.h&quot;<br><br>#if defined(__cplusplus) && __cplusplus<br>&nbsp;extern &quot;C&quot; {<br>#endif<br><br>char *trim (char *str)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char *ibuf, *obuf;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (str)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (ibuf = obuf = str; *ibuf; )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (*ibuf && (isspace (*ibuf)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ibuf++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (*ibuf && (obuf != str))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*(obuf++) = ' ';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while (*ibuf && (!isspace (*ibuf)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*(obuf++) = *(ibuf++);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*obuf = NUL;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (str);<br>}<br><br>#if defined(__cplusplus) && __cplusplus<br>&nbsp;}<br>#endif<br><br>#ifdef TEST<br><br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br><br>int main (int argc, char *argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (argc == 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf (&quot;trim(\&quot;%s\&quot;)\n&quot;, argv[1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf (&quot;returned \&quot;%s\&quot;\n&quot;, trim (argv[1]));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;To test this function, call TRIM\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;with an argument enclosed in quotes.\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;&nbsp;&nbsp;&nbsp;Example:\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;&nbsp;&nbsp;&nbsp;C:\\&gt;trim \&quot;&nbsp;&nbsp;test&nbsp;&nbsp;&nbsp;test&nbsp;&nbsp;&nbsp;\&quot;\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;&nbsp;&nbsp;&nbsp;trim(\&quot;&nbsp;&nbsp;test&nbsp;&nbsp;&nbsp;test&nbsp;&nbsp;&nbsp;\&quot;\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;&nbsp;&nbsp;&nbsp;returned \&quot;test test\&quot;\n\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf (stderr, &quot;&nbsp;&nbsp;&nbsp;C:\\&gt;_\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return EXIT_SUCCESS;<br>}<br><br>#endif /* TEST */<br><br><br>// Fule Sniptype.h------------------------------------<br><br>/*<br>**&nbsp;&nbsp;SNIPTYPE.H - Include file for SNIPPETS data types and commonly used macros<br>*/<br><br>#ifndef SNIPTYPE__H<br>#define SNIPTYPE__H<br><br>#include &lt;stdlib.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* For free()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br>#include &lt;string.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* For NULL & strlen()&nbsp;&nbsp;*/<br><br>typedef enum {Error_ = -1, Success_, False_ = 0, True_} Boolean_T;<br><br>#if !defined(WIN32) && !defined(_WIN32) && !defined(__NT__) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&& !defined(_WINDOWS)<br>&nbsp;#if !defined(OS2)<br>&nbsp;&nbsp;typedef unsigned char&nbsp;&nbsp;BYTE;<br>&nbsp;&nbsp;typedef unsigned long&nbsp;&nbsp;DWORD;<br>&nbsp;#endif<br>&nbsp;typedef unsigned short WORD;<br>#else<br>&nbsp;#define WIN32_LEAN_AND_MEAN<br>&nbsp;#define NOGDI<br>&nbsp;#define NOSERVICE<br>&nbsp;#undef INC_OLE1<br>&nbsp;#undef INC_OLE2<br>&nbsp;#include &lt;windows.h&gt;<br>&nbsp;#define HUGE<br>#endif<br><br>#define NUL '\0'<br>#define LAST_CHAR(s) (((char *)s)[strlen(s) - 1])<br>#define TOBOOL(x) (!(!(x)))<br>#define FREE(p) (free(p),(p)=NULL)<br><br>#endif /* SNIPTYPE__H */<br><br><br><br><br>------------<br>// Extkword.h file<br><br>/*====================================================================<br><br>&nbsp;&nbsp;&nbsp;&nbsp;_MSC_VER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Microsoft C 6.0 and later<br>&nbsp;&nbsp;&nbsp;&nbsp;_QC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Microsoft Quick C 2.51 and later<br>&nbsp;&nbsp;&nbsp;&nbsp;__TURBOC__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Borland Turbo C, Turbo C++ and BC++<br>&nbsp;&nbsp;&nbsp;&nbsp;__BORLANDC__&nbsp;&nbsp;&nbsp;&nbsp;Borland C++<br>&nbsp;&nbsp;&nbsp;&nbsp;__ZTC__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Zortech C and C++<br>&nbsp;&nbsp;&nbsp;&nbsp;__SC__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Symantec C++<br>&nbsp;&nbsp;&nbsp;&nbsp;__WATCOMC__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WATCOM C<br>&nbsp;&nbsp;&nbsp;&nbsp;__POWERC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mix Power C<br>&nbsp;&nbsp;&nbsp;&nbsp;__GNUC__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gnu C<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Revised:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;25-Sep-95&nbsp;&nbsp;Bob Stout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Original from PC-PORT.H<br>&nbsp;&nbsp;&nbsp;&nbsp;30-Mar-96&nbsp;&nbsp;Ed Blackman&nbsp;&nbsp;OS/2 mods for OS/2 ver 2.0 and up<br>&nbsp;&nbsp;&nbsp;&nbsp;30-May-96&nbsp;&nbsp;Andrew Clarke&nbsp;&nbsp;Added support for WATCOM C/C++ __NT__ macro.<br>&nbsp;&nbsp;&nbsp;&nbsp;17-Jun-96&nbsp;&nbsp;Bob Stout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Added __FLAT__ macros support<br>&nbsp;&nbsp;&nbsp;&nbsp;20-Aug-96&nbsp;&nbsp;Bob Stout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Eliminate Win32 conflicts<br>======================================================================*/<br><br><br>/* prevent multiple inclusions of this header file */<br><br>#ifndef EXTKWORD__H<br>#define EXTKWORD__H<br><br>#include &lt;limits.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* For INT_MAX, LONG_MAX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br><br>/*<br>**&nbsp;&nbsp;Watcom defines __FLAT__ for 32-bit environments and so will we<br>*/<br><br>#if !defined(__FLAT__) && !defined(__WATCOMC__) && !defined(_MSC_VER)<br>&nbsp;#if defined(__GNUC__)<br>&nbsp;&nbsp;#define __FLAT__ 1<br>&nbsp;#elif defined (_WIN32) ¦¦ defined(WIN32) ¦¦ defined(__NT__)<br>&nbsp;&nbsp;#define __FLAT__ 1<br>&nbsp;#elif defined(__INTSIZE)<br>&nbsp;&nbsp;#if (4 == __INTSIZE)<br>&nbsp;&nbsp;&nbsp;#define __FLAT__ 1<br>&nbsp;&nbsp;#endif<br>&nbsp;#elif (defined(__ZTC__) && !defined(__SC__)) ¦¦ defined(__TURBOC__)<br>&nbsp;&nbsp;#if ((INT_MAX != SHRT_MAX) && (SHRT_MAX == 32767))<br>&nbsp;&nbsp;&nbsp;#define __FLAT__ 1<br>&nbsp;&nbsp;#endif<br>&nbsp;#endif<br>#endif<br><br>/*<br>**&nbsp;&nbsp;Correct extended keywords syntax<br>*/<br><br>#if defined(__OS2__)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* EBB: not sure this works for OS/2 1.x */<br>&nbsp;#include &lt;os2def.h&gt;<br>&nbsp;#define INTERRUPT<br>&nbsp;#define HUGE<br>#elif defined(_WIN32) ¦¦ defined(WIN32) ¦¦ defined(__NT__)<br>&nbsp;#define WIN32_LEAN_AND_MEAN<br>&nbsp;#define NOGDI<br>&nbsp;#define NOSERVICE<br>&nbsp;#undef INC_OLE1<br>&nbsp;#undef INC_OLE2<br>&nbsp;#include &lt;windows.h&gt;<br>&nbsp;#define INTERRUPT<br>&nbsp;#define HUGE<br>#else /* ! Win 32 or OS/2 */<br>&nbsp;#if (defined(__POWERC) ¦¦ (defined(__TURBOC__) && !defined(__BORLANDC__)) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦¦ (defined(__ZTC__) && !defined(__SC__))) && !defined(__FLAT__)<br>&nbsp;&nbsp;#define FAR far<br>&nbsp;&nbsp;#define NEAR near<br>&nbsp;&nbsp;#define PASCAL pascal<br>&nbsp;&nbsp;#define CDECL cdecl<br>&nbsp;&nbsp;#if (defined(__ZTC__) && !defined(__SC__)) ¦¦ (defined(__SC__) && \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(__SC__ &lt; 0x700))<br>&nbsp;&nbsp;&nbsp;#define HUGE far<br>&nbsp;&nbsp;&nbsp;#define INTERRUPT<br>&nbsp;&nbsp;#else<br>&nbsp;&nbsp;&nbsp;#define HUGE huge<br>&nbsp;&nbsp;&nbsp;#define INTERRUPT interrupt<br>&nbsp;&nbsp;#endif<br>&nbsp;#else<br>&nbsp;&nbsp;#if (defined(__MSDOS__) ¦¦ defined(MSDOS)) && !defined(__FLAT__)<br>&nbsp;&nbsp;&nbsp;#define FAR _far<br>&nbsp;&nbsp;&nbsp;#define NEAR _near<br>&nbsp;&nbsp;&nbsp;#define HUGE _huge<br>&nbsp;&nbsp;&nbsp;#define PASCAL _pascal<br>&nbsp;&nbsp;&nbsp;#define CDECL _cdecl<br>&nbsp;&nbsp;&nbsp;#define INTERRUPT _interrupt<br>&nbsp;&nbsp;#else<br>&nbsp;&nbsp;&nbsp;#define FAR<br>&nbsp;&nbsp;&nbsp;#define NEAR<br>&nbsp;&nbsp;&nbsp;#define HUGE<br>&nbsp;&nbsp;&nbsp;#define PASCAL<br>&nbsp;&nbsp;&nbsp;#define CDECL<br>&nbsp;&nbsp;#endif<br>&nbsp;#endif<br>#endif<br><br>#endif /* EXTKWORD__H */<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top