delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/03/05/06:00:31

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Vijay Kumar R Zanvar" <vijoeyz AT hotpop DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: snprintf error
Date: Fri, 5 Mar 2004 16:17:38 +0530
Lines: 50
Message-ID: <c29lrm$1qn5kr$1@ID-203837.news.uni-berlin.de>
NNTP-Posting-Host: 61.11.64.74
X-Trace: news.uni-berlin.de 1078483639 61576859 I 61.11.64.74 ([203837])
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

F:\Vijay\C> type string.c

/* string.c - print sub-strings of random length */
#if  !defined ( __STDC__ ) || !defined ( __STDC_VERSION__ )
#error The compiler is not C99 compliant
#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define TIMES 5

int
main ( void )
{
    const char *str = ( const char [] ) { "Calvin and Hobbes" };
    srand ( time ( NULL ) );

    int len = strlen ( str );
    char *another_string =  malloc ( len + 1 );

    if ( another_string )
    {
        for ( int i = 0; i < TIMES; i++ )
        {
            int rand_len = rand () % len;
            rand_len = snprintf ( another_string, rand_len, "%s", str );
            another_string[rand_len] = '\0'; /* not really required */
            puts ( another_string );
        }
        free ( another_string );
        return EXIT_SUCCESS;
    }
    return EXIT_FAILURE;
}

F:\Vijay\C> gcc -std=c99 -Wall
string.c: In function `main':
string.c:27: warning: implicit declaration of function `snprintf'
f:/vijay/djgpp/tmp/cceCfRI9.o(.text+0xcd):string.c: undefined reference to `_snprintf'
collect2: ld returned 1 exit status

--
Vijay Kumar R Zanvar
Calvin - http://www.geocities.com/vijoeyz/misc/calvin/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019