integer - Convert Linux C Char Array to Int -


Need some advice on this as IM struggles for conflict and can not understand it.

I have a file that gets updated on a PC, indicating that the system was run and at what time it ran I am writing a very simple Linux console app (finally Will be a Nagian plugin). Who reads this file and responds based on what is found inside the file.

I am a new beginner to use programming on C and C. Please be patient and if you interpret any answer, it will be really appreciated.

Basically, I want to change a four array of 5 characters in an integer, although the 5th letter in the array is always a letter. So technically all I want to do is convert the first 4 characters into an integer array ... how ?? Ive tried many ways without any success, my problem is that at present I do not have a good understanding of language so there is no real idea what it can do or can not do.

Here is the source of my program

3455Y (Number will be random but will always be 4 characters long)

Basically a string taken from the Buff Array file will be that which <

 include    

Include & lt; Unistd.h & gt; Include & lt; Stdio.h & gt; Include & lt; Stdlib.h & gt; & Lt; Time.h> Include & lt; String H & gt; Include Define Corpidode 0644 Int main (int argi, four * argv []) {int i, nRead, fd; Int source; Int STATE_OK = 0; Int STATE_WARNING = 1; Int STATE_CRITICAL = 2; Int STATE_UNKNOWN = 3; Int system_paused = 0; Four buff [5]; Int testnumber; If ((FD = Open (RGR [1], O_RDNL)) == -1) {printf ("unsuccessful:% s", argv [1]); Return STATE_UNKNOWN; } Else {nRead = read (fd, buf, 5); } Closed (source); If (Buff [4] == 'P') {printf ("Software Paused"); Return STATE_WARNING; } And {return STATE_OK; } Time_t ltime; / * Calendar time * / structure TM * tm; Ltime = time (zero); / * Get current call time * / tt = local time (& amp; ltime); Int test; Test = TM-> TM_Hour + TM-> TM_man; Printf ("% d", test); Printf ("% d", strto (buff)); }

You can use atoi

atoi one Gives four * logic and an int if the string is empty, or the first letter is not a number or zero sign, then atoi returns 0. If atoi gets a non-numeric character, then it gives the number formed to that point < / P>

  intimate = atoy (buff);  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -