RyanRahl's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 8 (0.02 per day)
- Joined:
- 26-March 12
- Profile Views:
- 278
- Last Active:
Apr 06 2012 04:01 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Linux
- Favorite Browser:
- Opera
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Subaru
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Program exiting without taking all fgets inputs
Posted 6 Apr 2012
That was a very clear and concise explanation, thank you again.
and this:
Quote
Also on your last variable you are using a constant to determine the size, it is usually considered better to define a constant and use that definition instead that constant. Then you use that constant instead of the number. Then if you need to change the size later you only need to change it once. Also I don't recommend you learn to use sizeof() for determining the size of an array yet. For now use a constant and then use that constant when you need the size. The sizeof() function has several uses and it can be hard to tell what use you are actually using.
makes a lot of sense. I had to read it a few times but I definitely see what you mean and why you say it. Thanks. -
In Topic: Program exiting without taking all fgets inputs
Posted 6 Apr 2012
Quote
Part of your problem is that your array is not large enough to hold your entry string. The size of your array is 4 and you have 3 characters in your entry "m2k" which would be large enough except fgets() also extracts the end of line character and places that into your string which does not leave room for your end of string character. So you need to increase the size of your array. I would suggest a much larger number, maybe 100. You will also need to remove this end of line character from your string before you do your comparison.
OK, so I increased the size of the array and modified the user input part to look like this:
printf("Enter Desired Operation: "); fgets(conversion, sizeof(conversion), stdin); conversion[strlen(conversion) -1] = '\0';
and everything works like I want it to. But I am confused as to why 4 is not large enough array. I thought that the string had one end of line character at the end. So is there and end of line AND end of string character? Also you said:
Quote
Also you should stop using global variables and learn how to pass the required variables to and from your functions.
and I'm not sure what you mean by that. I should disclose that I am VERY new to this. I picked up the book "Practical C Programming" and this program is an exercise at the end of chapter 7. So everything from chapter 1 until now is the extent of my knowledge. I will be very grateful for any further explanation or advice, I'm really trying to soak up as much as possible. Thanks for your help. -
In Topic: I need a port that is always open whenever my computer is on
Posted 6 Apr 2012
If I were in your position and I wanted to know if my remote machine was on but didn't want to rely on a piece of software running to accomplish it I would simply set my firewall to "REJECT" packets on a firewalled port instead of "DROP"
This way you could use something like nmap to determine if your machine is on by:
nmap -sS [Remote IP] -p[random port]
and if the result comes back as "closed" then the firewall has rejected the packet and sent back a packet with the "RST" flag. If it's sending packets, the machine is on.
and if the result comes back as "filtered" then your machine is off because it will have sent back no packets (unless your firewall is configured to "DROP" then nmap will have no way of knowing if the machine is off or if the firewall is set to "DROP") -
In Topic: Question about data type error from a newbie
Posted 27 Mar 2012
Quote
In my opinion, using the strcpy function would be easier
Yes, that was perfect. I forgot about the strcpy, I remembered the need for the null character at the end and I defined space for that in the array when I declared the variable but overlooked the fact that character strings in the format I was using is not part of the standard library. I added "#include <string.h>" to the preproccessor and used "strcpy" and everything went perfectly. Thanks! -
In Topic: Question about data type error from a newbie
Posted 27 Mar 2012
Quote
I might be a missing something, but why are you scanning to char and then converting it to int?
Why not just ask for a score and scan to int.
The only answer I have for that is that the book I am going through taught me that way. I'm going to guess it taught me that way because when dealing with input from a user, it can't be assumed the user will always input a type of data that is compatible with what is in the program. So to make up for that, I start as a char because that could be anything from the keyboard and then safely convert it into something the program can use. I could be wrong though, I'm pretty new to this.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Location:
- Pacific Northwest
- Interests:
- Programming, Linux, Playing Drums, Music Theory, Reading, Politics and general man stuff
- Full Name:
- Ryan
- Years Programming:
- 0
- Programming Languages:
- sh, C
Contact Information
- E-mail:
- Private
Friends
RyanRahl hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
RyanRahl has no profile comments yet. Why not say hello?