Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.c
  3. //  OS HW 1
  4. //
  5. //  Created by drew mcdaniel on 2/11/16.
  6. //
  7. //
  8.  
  9. #include <stdio.h>
  10.  
  11. char* concat_strings(char** strings);
  12.  
  13. int main(int argc, char** argv){
  14.    
  15.     //TODO: first make sure the proper # of arguments are passed
  16.     if (argv == NULL) {
  17.         printf("ERROR");
  18.     }
  19.    
  20.     //argc is argument count, default 1 (filepath)
  21.     //argv is array of arguments passed in
  22.    
  23.     printf("%s is the first string %s is the second string\n", argv[1], argv[2]);
  24.     //prints inputted strings
  25.    
  26.    
  27.     concat_strings(argv);
  28.    
  29.     return 0;
  30. }
  31.  
  32. char* concat_strings(char** strings){
  33.     char* str;
  34.     str = (char*) malloc(80);
  35.    
  36.     strings++;
  37.    
  38.     /* Initial memory allocation */
  39.     str = *strings;
  40.     printf("String = %s\n", str);
  41.    
  42.     while (strings != 0) {
  43.         /* Reallocating memory */
  44.         strings++;
  45.         str = (char*) realloc(str, 80);
  46.        
  47.         while(*str != 0){
  48.             if (str == 0) {
  49.                 str = " ";
  50.                 str++;
  51.                 str = *strings;
  52.             }else{
  53.                 str++;
  54.             }
  55.         }
  56.        
  57.         printf("String = %s\n", str);
  58.     }
  59.    
  60.    
  61.     return str;
  62.     /*
  63.     char* final = strings[2]-1;
  64.     final = " ";
  65.     return strings[1];
  66.      */
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement