"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

test-printf.c File Reference

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

Include dependency graph for alpha/src/test-printf.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define DEC   -123
 

Definition at line 98 of file alpha/src/test-printf.c.

Referenced by fp_test().

#define FORMAT   "|%12.4f|%12.4e|%12.4g|\n"
 

#define INT   255
 

Definition at line 99 of file alpha/src/test-printf.c.

Referenced by fp_test().

#define UNS   (~0)
 

Definition at line 100 of file alpha/src/test-printf.c.

Referenced by fp_test().


Function Documentation

void fmtchk char *    fmt
 

Definition at line 57 of file alpha/src/test-printf.c.

References sccsid.

00058 {
00059   static char *sccsid = "this is a test...";
00060   (void) fputs(fmt, stdout);
00061   (void) printf(":\t`");
00062   (void) printf(fmt, 0x12);
00063   (void) printf("'\n");
00064 }

void fmtst1chk char *    fmt
 

Definition at line 67 of file alpha/src/test-printf.c.

00068 {
00069   (void) fputs(fmt, stdout);
00070   (void) printf(":\t`");
00071   (void) printf(fmt, 4, 0x12);
00072   (void) printf("'\n");
00073 }

void fmtst2chk char *    fmt
 

Definition at line 76 of file alpha/src/test-printf.c.

00077 {
00078   (void) fputs(fmt, stdout);
00079   (void) printf(":\t`");
00080   (void) printf(fmt, 4, 4, 0x12);
00081   (void) printf("'\n");
00082 }

double FooBar int    a
 

Definition at line 40 of file alpha/src/test-printf.c.

References a, and xxyyz.

00041 {
00042   return xxyyz[a].b;
00043 }

double FooFoo int    a
 

Definition at line 48 of file alpha/src/test-printf.c.

References a, uxxe, and zzz.

00049 {
00050   zzz++;
00051   return uxxe[a];
00052 }

void fp_test void   
 

Definition at line 108 of file alpha/src/test-printf.c.

References DEC, INT, and UNS.

00109 {
00110   int i, j, k, l;
00111   char buf[7];
00112   char *prefix = buf;
00113   char tp[20];
00114 
00115   puts("\nFormatted output test");
00116   printf("prefix  6d      6o      6x      6X      6u\n");
00117   strcpy(prefix, "%");
00118   for (i = 0; i < 2; i++) {
00119     for (j = 0; j < 2; j++) {
00120       for (k = 0; k < 2; k++) {
00121         for (l = 0; l < 2; l++) {
00122           strcpy(prefix, "%");
00123           if (i == 0) strcat(prefix, "-");
00124           if (j == 0) strcat(prefix, "+");
00125           if (k == 0) strcat(prefix, "#");
00126           if (l == 0) strcat(prefix, "0");
00127           printf("%5s |", prefix);
00128           strcpy(tp, prefix);
00129           strcat(tp, "6d |");
00130           printf(tp, DEC);
00131           strcpy(tp, prefix);
00132           strcat(tp, "6o |");
00133           printf(tp, INT);
00134           strcpy(tp, prefix);
00135           strcat(tp, "6x |");
00136           printf(tp, INT);
00137           strcpy(tp, prefix);
00138           strcat(tp, "6X |");
00139           printf(tp, INT);
00140           strcpy(tp, prefix);
00141           strcat(tp, "6u |");
00142           printf(tp, UNS);
00143           printf("\n");
00144         }
00145       }
00146     }
00147   }
00148   printf("%10s\n", (char *) NULL);
00149   printf("%-10s\n", (char *) NULL);
00150 }

int main void   
 

Definition at line 153 of file alpha/src/test-printf.c.

References d, fmtchk(), fmtst1chk(), fmtst2chk(), and fp_test().

00154 {
00155   static char shortstr[] = "Hi, Z.";
00156   static char longstr[] = "Good morning, Doctor Chandra.  This is Hal.  \
00157 I am ready for my first lesson today.";
00158 
00159   fmtchk("%.4x");
00160   fmtchk("%04x");
00161   fmtchk("%4.4x");
00162   fmtchk("%04.4x");
00163   fmtchk("%4.3x");
00164   fmtchk("%04.3x");
00165 
00166   fmtst1chk("%.*x");
00167   fmtst1chk("%0*x");
00168   fmtst2chk("%*.*x");
00169   fmtst2chk("%0*.*x");
00170 
00171 #ifndef BSD
00172   printf("bad format:\t\"%z\"\n");
00173   printf("nil pointer (padded):\t\"%10p\"\n", (void *) NULL);
00174 #endif
00175 
00176   printf("decimal negative:\t\"%d\"\n", -2345);
00177   printf("octal negative:\t\"%o\"\n", -2345);
00178   printf("hex negative:\t\"%x\"\n", -2345);
00179   printf("long decimal number:\t\"%ld\"\n", -123456);
00180   printf("long octal negative:\t\"%lo\"\n", -2345L);
00181   printf("long unsigned decimal number:\t\"%lu\"\n", -123456);
00182   printf("zero-padded LDN:\t\"%010ld\"\n", -123456);
00183   printf("left-adjusted ZLDN:\t\"%-010ld\"\n", -123456);
00184   printf("space-padded LDN:\t\"%10ld\"\n", -123456);
00185   printf("left-adjusted SLDN:\t\"%-10ld\"\n", -123456);
00186 
00187   printf("zero-padded string:\t\"%010s\"\n", shortstr);
00188   printf("left-adjusted Z string:\t\"%-010s\"\n", shortstr);
00189   printf("space-padded string:\t\"%10s\"\n", shortstr);
00190   printf("left-adjusted S string:\t\"%-10s\"\n", shortstr);
00191   printf("null string:\t\"%s\"\n", (char *)NULL);
00192 #if 0
00193   printf("limited string:\t\"%.22s\"\n", longstr);
00194 #endif
00195 
00196   printf("e-style >= 1:\t\"%e\"\n", 12.34);
00197   printf("e-style >= .1:\t\"%e\"\n", 0.1234);
00198   printf("e-style < .1:\t\"%e\"\n", 0.001234);
00199   printf("e-style big:\t\"%.60e\"\n", 1e20);
00200   printf ("e-style == .1:\t\"%e\"\n", 0.1);
00201   printf("f-style >= 1:\t\"%f\"\n", 12.34);
00202   printf("f-style >= .1:\t\"%f\"\n", 0.1234);
00203   printf("f-style < .1:\t\"%f\"\n", 0.001234);
00204   printf("g-style >= 1:\t\"%g\"\n", 12.34);
00205   printf("g-style >= .1:\t\"%g\"\n", 0.1234);
00206   printf("g-style < .1:\t\"%g\"\n", 0.001234);
00207   printf("g-style big:\t\"%.60g\"\n", 1e20);
00208 
00209   {
00210     char buf[128];
00211     sprintf(buf, "new test: %.15g", 99.85);
00212     printf(":%s:\n", buf);
00213   }
00214 
00215   printf (" %6.5lf\n", .099999999860301614);
00216   printf (" %6.5lf\n", .1);
00217   printf ("x%5.4lfx\n", .5);
00218 
00219   printf ("%#03x\n", 1);
00220 
00221 #if 0                           /* XXX printf_fp still broken */
00222   {
00223     double d = FLT_MIN;
00224     int niter = 17;
00225     
00226     while (niter-- != 0)
00227       printf ("%.17e\n", d / 2);
00228     fflush (stdout);
00229   }
00230 
00231   printf ("%15.5e\n", 4.9406564584124654e-324);
00232 #endif
00233 
00234 #define FORMAT "|%12.4f|%12.4e|%12.4g|\n"
00235   printf (FORMAT, 0.0, 0.0, 0.0);
00236   printf (FORMAT, 1.0, 1.0, 1.0);
00237   printf (FORMAT, -1.0, -1.0, -1.0);
00238   printf (FORMAT, 100.0, 100.0, 100.0);
00239   printf (FORMAT, 1000.0, 1000.0, 1000.0);
00240   printf (FORMAT, 10000.0, 10000.0, 10000.0);
00241   printf (FORMAT, 12345.0, 12345.0, 12345.0);
00242   printf (FORMAT, 100000.0, 100000.0, 100000.0);
00243   printf (FORMAT, 123456.0, 123456.0, 123456.0);
00244 #undef  FORMAT
00245 
00246 #if 0
00247   {
00248     char buf[20];
00249     printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n",
00250             snprintf (buf, sizeof (buf), "%30s", "foo"), sizeof (buf), buf);
00251   }
00252 #endif
00253 
00254   fp_test ();
00255   fp_test ();
00256   fp_test ();
00257   fp_test ();
00258   fp_test ();
00259   fp_test ();
00260   fp_test ();
00261   fp_test ();
00262 
00263   printf ("%e should be 1.234568e+06\n", 1234567.8);
00264   printf ("%f should be 1234567.800000\n", 1234567.8);
00265   printf ("%g should be 1.23457e+06\n", 1234567.8);
00266   printf ("%g should be 123.456\n", 123.456);
00267   printf ("%g should be 1e+06\n", 1000000.0);
00268   printf ("%g should be 10\n", 10.0);
00269   printf ("%g should be 0.02\n", 0.02);
00270 
00271   {
00272     char buf[128];
00273     sprintf(buf, "%#.*f", 4, (double)0.70000);
00274     printf("testing parametric fields: %s\n", buf);
00275   }
00276 
00277   return(0);
00278 }


Variable Documentation

int a
 

Definition at line 31 of file alpha/src/test-printf.c.

Referenced by FooBar(), and FooFoo().

double b
 

Definition at line 32 of file alpha/src/test-printf.c.

double c
 

Definition at line 33 of file alpha/src/test-printf.c.

char d
 

Definition at line 34 of file alpha/src/test-printf.c.

Referenced by main().

char* sccsid = "this is a test..." [static]
 

Definition at line 54 of file alpha/src/test-printf.c.

Referenced by fmtchk().

double uxxe[100]
 

Definition at line 45 of file alpha/src/test-printf.c.

Referenced by FooFoo().

struct { ... } xxyyz[100]
 

Referenced by FooBar().

int zzz
 

Definition at line 37 of file alpha/src/test-printf.c.

Referenced by FooFoo().



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214