All pastes #183956 Raw Edit

Anonymous

public c v1 · immutable
#183956 ·published 2006-09-27 12:06 UTC
rendered paste body
#include <stdio.h>#include <string.h>intmain(int argc, char **argv) {  char *sentence =  "500053 This is a string";  char *vhost;  char str1[8] ="";  int i;  //for(i=0;i < strlen(sentence) && sentence[i] != 32; i++);   for(i=0;sentence[i] != 0 && sentence[i] != 32; i++);  printf("stop-char(%d): '%c'\n",i,sentence[i-1]);  vhost = strncpy(str1,sentence,i);  char logentry[sizeof(sentence)-sizeof(vhost)];  for(++i; i < strlen(sentence); i++) {    logentry[i] = sentence[i];    printf("logentry[%c] = sentence[%c]\n",logentry[i],sentence[i]);  }  printf("input is: %s\n",sentence);  printf("vhost is: '%s'\n",vhost);  printf("logentry is: '%s'\n",logentry);}------------------- OUTPUT --------------------db@gonzalez:~>./teststop-char(6): '3'logentry[T] = sentence[T]logentry[h] = sentence[h]logentry[i] = sentence[i]logentry[s] = sentence[s]logentry[ ] = sentence[ ]logentry[i] = sentence[i]logentry[s] = sentence[s]logentry[ ] = sentence[ ]logentry[a] = sentence[a]logentry[ ] = sentence[ ]logentry[s] = sentence[s]logentry[t] = sentence[t]logentry[r] = sentence[r]logentry[i] = sentence[i]logentry[n] = sentence[n]logentry[g] = sentence[g]input is: 500053 This is a stringvhost is: '500053'logentry is: 'F'