Recent content by TheSourceCode

  1. T

    Pascal's Triangle: Pointers and Dynamic Memory Allocation

    triangle[i][i+1]=1; It's this line isn't it? Thanks, I'll fix that now. EDIT: I did it again here. for(j=1; j<i+1; j++) Should be corrected in the OP now.
  2. T

    Pascal's Triangle: Pointers and Dynamic Memory Allocation

    Here is the given problem. I have a question for part c and e. Calculate and print first 12 rows of the famous Pascal triangle, as shown below. Each number is the sum of the two numbers immediately above it. As our intent is to practice pointers, functions, loops, and dynamic memory...
  3. T

    Parsing command line arguments in C

    Thanks for the feedback everyone, I got it to work! I really should have noticed the issue before.
  4. T

    Parsing command line arguments in C

    Sorry, let me clarify a little. Valid input would look something like this: program.exe John Doe -age 43 or program.exe -age 56 Jane Doe or program.exe Bob Smith Where program.exe is argument 0 and so on...
  5. T

    Parsing command line arguments in C

    Here is the given assignment: Write a code that would parse the command line and display the user’s first / last name and (if given) his/her age. The ‘-age’ key, if present, could be the first or, alternatively, the third argument and indicates that the following parameter is age, as in the...
  6. T

    Error Checking in C: Understanding the If Statement Condition

    Yeah, valid_input was an integer variable. And I think the ! in front of the int is what confused me. I had done it another way but this was how the prof did it in his solution. I was just trying to understand why his way worked also.
  7. T

    Error Checking in C: Understanding the If Statement Condition

    Thanks everyone. I did learn at some point that scanf returns a value but must have forgotten. Makes sense now.
  8. T

    Error Checking in C: Understanding the If Statement Condition

    I have the following chunk of C code that checks for errors. Works fine but I don't understand why it works. printf("\nEnter the number of students\n"); valid_input = scanf("%d", &snum); if(!valid_input){ printf("\nInvalid number of students\n"); system("pause"); return 1; } The...
  9. T

    Converting String to Int in C: Issues with atoi() and isdigit() | Code Solution

    I wasn't able to figure out how to track variables in a debugger. However, the due date was extended so I will sit down this weekend and try to figure it out. Also, I'll have another chance to talk to the prof tomorrow. We've not done anything with pointers so I'm not sure if that's an option...
  10. T

    Converting String to Int in C: Issues with atoi() and isdigit() | Code Solution

    I need to take the values from a string , such as {23 45 67\0}, and store them into an int array. I need to do this with atoi() and isdigit() but I'm having some issues. Here is what I have. for(i=0; i<=n; i++){ num[i]=atoi(str); for(j=0; (isdigit(str[j])!=0); j++){...
  11. T

    Cyclic Permutation in C: Create Alphabet Pattern with Nested For Loops

    Thanks a lot. Took me a bit to get the wrap around to work properly but I got it. I don't think modulo was very intuitive to me before but now I get it.
  12. T

    Cyclic Permutation in C: Create Alphabet Pattern with Nested For Loops

    Use nested for loops to produce the following pattern of cyclic permutations of the English alphabet: abcde...yz bcdef...za cdef...zab ... zabcde...xy HINT: you may find the modulo (remainder) operator % useful. I have an idea of how to do this but it would not use the modulo operator...
  13. T

    Light & Shadows: Read in Shadow but Not the Dark?

    So the larger the room the harder it would be to read?
  14. T

    Light & Shadows: Read in Shadow but Not the Dark?

    I was reading the other day with the light on behind me. I cast a shadow over the book I was reading and was still able to read it (not that surprising). I'd never thought about this before though. Why is it you can read in a shadow but not the dark? I could understand if there was another...
Back
Top