- 
                Notifications
    You must be signed in to change notification settings 
- Fork 20
Oscar So #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            oscarso2000
  wants to merge
  4
  commits into
  CPRO-Session1:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
oscarso2000:master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Oscar So #18
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            4 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Oscar So | ||
| 1. First one means, ++(*p) adds one before implementing pointer. Second one is (*P++), but precedence of ++ is treated before P. Last one is similar to the second one, but it is treated as (*++P) where the compiler looks for associativity. | ||
| 2. I think both do not guarentee operator precedence, this is because in postfix, &&, ||, mathematical functions, comparison, the computer code reads it from left to right. However, for conditions, assignment of variables, and prefixes, the code goes from right to left. | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right! 💯 | ||
| 3. Advantages of pointers are when handling arrays, and data tables. They allow references to functions, and can return multiple variables and values. | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right! 👍 | ||
| 4. I am a bit clueless on number 4 and would like some explanation. Thanks. | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include<stdio.h> | ||
| #include<string.h> | ||
| void reverse(char *input){ | ||
| int length, i; | ||
| char *start, *stop, temp; | ||
| length = strlen(input); | ||
| start=input; | ||
| stop=input; | ||
| for(i=0;i<length-1;i++){ | ||
| stop++; | ||
| } | ||
| for(i=0;i<length/2;i++){ | ||
| temp=*stop; | ||
| *stop=*start; | ||
| *start=temp; | ||
| start++; | ||
| stop--; | ||
| } | ||
| } | ||
| int main() { | ||
| char input[200]; | ||
| printf("Please input string: \n"); | ||
| fgets(input,sizeof(input),stdin); | ||
| strtok(input,"\n"); | ||
| reverse(input); | ||
| printf("The reverse is: \n"); | ||
| printf("%s \n", input); | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #include<stdio.h> | ||
| #include<string.h> | ||
| char *cat (char *p1, char *p2){ | ||
| int i=0, p3= strlen(p1); | ||
| while(p2[i]!='\0'){ | ||
| p1[p3]=p2[i]; | ||
| p3++; | ||
| i++; | ||
| } | ||
| p1[p3]='\0'; | ||
| return p1; | ||
| } | ||
|  | ||
| int main(){ | ||
| char p1[50], p2[50]; | ||
| printf("Enter first string: "); | ||
| fgets(p1,sizeof(p1),stdin); | ||
| printf("Enter second string: "); | ||
| fgets(p2,sizeof(p2),stdin); | ||
| strtok(p1,"\n"); | ||
| strtok(p2,"\n"); | ||
| cat(p1,p2); | ||
| printf("New string: %s \n",p1); | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include<stdio.h> | ||
| #include<string.h> | ||
| int compare(char *p1, char *p2){ | ||
| while (*p1==*p2){ | ||
| if (*p1 == '\0' || *p2 == '\0'){ | ||
| printf("Dissimilar User Input \n Error \n"); | ||
| break; | ||
| } | ||
| p1++; | ||
| p2++; | ||
| } | ||
| if (*p1=='\0' && *p2 == '\0'){ | ||
| return 0; | ||
| }else if (*p1=='\0'){ | ||
| return 1; | ||
| }else if (*p2 == '\0'){ | ||
| return -1; | ||
| } | ||
| } | ||
| int main () { | ||
| int result; | ||
| char p1 [100], p2 [100], final; | ||
| printf("Input first string: "); | ||
| fgets(p1, sizeof(p1),stdin); | ||
| printf("Input second string: "); | ||
| fgets(p2, sizeof(p2),stdin); | ||
| strtok(p2, "\n"); | ||
| strtok(p1, "\n"); | ||
| result = compare (p1,p2); | ||
| if (result == 0){ | ||
| printf("Both strings are the same. \n"); | ||
| }else if(result == -1) { | ||
| printf("Input 1 is longer than Input 2. \n"); | ||
| }else if (result ==1) { | ||
| printf("Input 1 is shorter than Input 2. \n"); | ||
| } | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! 👍