Advertisement
f30ghost

Pointers

Dec 11th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #define MAX_LEN 1000
  7.  
  8. ///Problem 6
  9.  
  10. void stringSplit(char string[], char *pntr[], unsigned len){
  11.     size_t i = 0, j = 0;
  12.     char ant  = ' ';
  13.     int k = 0;
  14.  
  15.     while(string[i] && (len != k)){
  16.         if(!isspace(string[i]) && isspace(ant)){
  17.             pntr[j] = &string[i];
  18.             j++;
  19.         }
  20.         ant = string[i];
  21.         i++;
  22.         k++;
  23.     }
  24.     pntr[i] = NULL;
  25. }
  26.  
  27.  
  28. int main(int argc, char **argv)
  29. {
  30.  
  31. /**problem 6 */
  32.  
  33. char string[MAX_LEN] = "This is it fams";
  34. char *pntr[15];
  35.  
  36. stringSlplit(s,p);
  37.  
  38. for(int i = 0; i != NULL; i++){
  39.     printf("%s",pntr[i], 15);
  40.  
  41.  
  42. /** End of Problem 6 */
  43.  
  44.     int pos = 1;
  45.     char **aux;
  46.  
  47.     for(int i = 0; i < argc; i++)
  48.         if(argv[i][0] == '-'){
  49.             printf("it entered the if \n");
  50.  
  51.             aux = argv[i][pos];
  52.             argv[i][0] = argv[i][pos];
  53.             argv[i][0] = aux;
  54.             pos++;
  55.         }
  56.  
  57.     for(int i = 0; i < argc; i++)
  58.         printf("%10s\n", argv[i]);
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement