Skip to content
  • Benoît Legat's avatar
    6595eda0
    Remove trailing whitespace in printf · 6595eda0
    Benoît Legat a rédigé
    The only tricky ones were
    Assembleur/src/gdb.c
    C/S3-src/strcat.c
    because they output something like
    1 2 3
    with
    for(i=0;i<n;i++) {printf("%d ",i);} printf("\n");
    What I commonly do in that case is
    for(i=0;i<n;i++) {printf("%d%c",i,(i+1==n)?'\n':' ');}
    but that can be considered as tricky for LSINF1252 so I've written
    for(i=0;i<n;i++) {printf(" %d",i);} printf("\n");
    which outputs
     1 2 3
    6595eda0
    Remove trailing whitespace in printf
    Benoît Legat a rédigé
    The only tricky ones were
    Assembleur/src/gdb.c
    C/S3-src/strcat.c
    because they output something like
    1 2 3
    with
    for(i=0;i<n;i++) {printf("%d ",i);} printf("\n");
    What I commonly do in that case is
    for(i=0;i<n;i++) {printf("%d%c",i,(i+1==n)?'\n':' ');}
    but that can be considered as tricky for LSINF1252 so I've written
    for(i=0;i<n;i++) {printf(" %d",i);} printf("\n");
    which outputs
     1 2 3
Chargement en cours