Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Get certain parts out of a string using C
  2. #include <stdio.h>  
  3. #include <string.h>  
  4. #include <windows.h>  
  5.  
  6. int main ()  
  7. {  
  8.     // in my application this comes from the handle and readfile
  9.     char buffer[255]="TEST999.UKPART=12999-0112...ISUE-125" ;    
  10.     //
  11.     int i;  
  12.     int codes[256];  
  13.     char *pos = buffer;  
  14.     size_t current = 0;  
  15.     //  
  16.        char buffer2[255];
  17.    if ((pos=strstr(pos, "UKPART")) != NULL) {  
  18.         strcpy (buffer2, pos); // buffer2 <= "UKPART=12999-0112...ISUE-125"
  19.    }
  20.  
  21.         printf("%sn", buffer2);  
  22.     system("pause");
  23.     return 0;  
  24. }
  25.        
  26. EXAMPLE:
  27.    char buffer[255]="IZTAG-12345...UKPART=12999-0112...ISUE-125" ;    
  28.    char buffer2[255];
  29.    if ((pos=strstr(pos, "UKPART")) != NULL) {  
  30.         strcpy (buffer2, pos); // buffer2 <= "UKPART=12999-0112...ISUE-125"