Search Results

Search found 1848 results on 74 pages for 'printf'.

Page 46/74 | < Previous Page | 42 43 44 45 46 47 48 49 50 51 52 53  | Next Page >

  • C/C++ line number

    - by Betamoo
    In the sake of debugging purposes, can I get the line number in C/C++ compilers? (standard way or specific ways for certain compilers) e.g if(!Logical) printf("Not logical value at line number %d \n",LineNumber); // How to get LineNumber without writing it by my hand?(dynamic compilation) Thanks

    Read the article

  • Basic data alignment question

    - by Broken Logic
    I've been playing around to see how my computer works under the hood. What I'm interested in is seeing is what happens on the stack inside a function. To do this I've written the following toy program: #include <stdio.h> void __cdecl Test1(char a, unsigned long long b, char c) { char c1; unsigned long long b1; char a1; c1 = 'b'; b1 = 4; a1 = 'r'; printf("%d %d - %d - %d %d Total: %d\n", (long)&b1 - (long)&a1, (long)&c1 - (long)&b1, (long)&a - (long)&c1, (long)&b - (long)&a, (long)&c - (long)&b, (long)&c - (long)&a1 ); }; struct TestStruct { char a; unsigned long long b; char c; }; void __cdecl Test2(char a, unsigned long long b, char c) { TestStruct locals; locals.a = 'b'; locals.b = 4; locals.c = 'r'; printf("%d %d - %d - %d %d Total: %d\n", (long)&locals.b - (long)&locals.a, (long)&locals.c - (long)&locals.b, (long)&a - (long)&locals.c, (long)&b - (long)&a, (long)&c - (long)&b, (long)&c - (long)&locals.a ); }; int main() { Test1('f', 0, 'o'); Test2('f', 0, 'o'); return 0; } And this spits out the following: 9 19 - 13 - 4 8 Total: 53 8 8 - 24 - 4 8 Total: 52 The function args are well behaved but as the calling convention is specified, I'd expect this. But the local variables are a bit wonky. My question is, why wouldn't these be the same? The second call seems to produce a more compact and better aligned stack. Looking at the ASM is unenlightening (at least to me), as the variable addresses are still aliased there. So I guess this is really a question about the assembler itself allocates the stack to local variables. I realise that any specific answer is likely to be platform specific. I'm more interested in a general explanation unless this quirk really is platform specific. For the record though, I'm compiling with VS2010 on a 64bit Intel machine.

    Read the article

  • Seg Fault with malloc'd pointers

    - by anon
    I'm making a thread class to use as a wrapper for pthreads. I have a Queue class to use as a queue, but I'm having trouble with it. It seems to allocate and fill the queue struct fine, but when I try to get the data from it, it Seg. faults. http://pastebin.com/Bquqzxt0 (the printf's are for debugging, both throw seg faults) edit: the queue is stored in a dynamically allocated "struct queueset" array as a pointer to the data and an index for the data

    Read the article

  • Assembly GDB Print String

    - by Ken
    So in assembly I declare the following String: Sample db "This is a sample string",0 In GDB I type "p Sample" (without quotes) and it spits out 0x73696854. I want the actual String to print out. So I tried "printf "%s", Sample" (again, without quotes) and it spits out "Cannot access memory at address 0x73696854." Short version: How do I print a string in GDB?

    Read the article

  • How to pass a variable to an awk print parameter...

    - by Jamie
    I'm trying extract the nth + 1 and nth + 3 columns from a file. This is what tried, which is a useful pseudo code: for i in {1..100} ; do awk -F "," " { printf \"%3d, %12.3f, %12.3f\\n\", \$1, \$($i+1), \$($i+3) } " All_Runs.csv > Run-$i.csv which, obviously doesn't work (but it seemed reasonable to hope). How can I do this?

    Read the article

  • How to set a default value in an IF snippet?

    - by kuti
    Hello, I have the following snippet in a bash script written in Solaris 10: printf "port(389)=" read PORT if [[ $PORT == "" ]]; then PORT=389 fi What I am trying to get that if the user hits the enter key, the Port should be set to 389. The snippet above does not seem to be working. Any suggestions?

    Read the article

  • C newbie malloc question

    - by roufamatic
    Why doesn't this print 5? void writeValue(int* value) { value = malloc(sizeof(int)); *value = 5; } int main(int argc, char * argv) { int* value = NULL; writeValue(value); printf("value = %d\n", *value); // error trying to access 0x00000000 } and how can I modify this so it would work while still using a pointer as an argument to writeValue?

    Read the article

  • Storing a NTFS Security Descriptor in C

    - by Doori Bar
    My goal is to store a NTFS Security Descriptor in its identical native state. The purpose is to restore it on-demand. I managed to write the code for that purpose, I was wondering if anybody mind to validate a sample of it? (The for loop represents the way I store the native descriptor) This sample only contains the flag for "OWNER", but my intention is to apply the same method for all of the security descriptor flags. I'm just a beginner, would appreciate the heads up. Thanks, Doori Bar #define _WIN32_WINNT 0x0501 #define WINVER 0x0501 #include <stdio.h> #include <windows.h> #include "accctrl.h" #include "aclapi.h" #include "sddl.h" int main (void) { DWORD lasterror; PSECURITY_DESCRIPTOR PSecurityD1, PSecurityD2; HANDLE hFile; PSID owner; LPTSTR ownerstr; BOOL ownerdefault; int ret = 0; unsigned int i; hFile = CreateFile("c:\\boot.ini", GENERIC_READ | ACCESS_SYSTEM_SECURITY, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hFile == INVALID_HANDLE_VALUE) { fprintf(stderr,"CreateFile() failed. Error: INVALID_HANDLE_VALUE\n"); return 1; } lasterror = GetSecurityInfo(hFile, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION , &owner, NULL, NULL, NULL, &PSecurityD1); if (lasterror != ERROR_SUCCESS) { fprintf(stderr,"GetSecurityInfo() failed. Error: %lu;\n", lasterror); ret = 1; goto ret1; } ConvertSidToStringSid(owner,&ownerstr); printf("ownerstr of PSecurityD1: %s\n", ownerstr); /* The for loop represents the way I store the native descriptor */ PSecurityD2 = malloc( GetSecurityDescriptorLength(PSecurityD1) * sizeof(unsigned char) ); for (i=0; i < GetSecurityDescriptorLength(PSecurityD1); i++) ((unsigned char *) PSecurityD2)[i] = ((unsigned char *) PSecurityD1)[i]; if (IsValidSecurityDescriptor(PSecurityD2) == 0) { fprintf(stderr,"IsValidSecurityDescriptor(PSecurityD2) failed.\n"); ret = 2; goto ret2; } if (GetSecurityDescriptorOwner(PSecurityD2,&owner,&ownerdefault) == 0) { fprintf(stderr,"GetSecurityDescriptorOwner() failed."); ret = 2; goto ret2; } ConvertSidToStringSid(owner,&ownerstr); printf("ownerstr of PSecurityD2: %s\n", ownerstr); ret2: free(owner); free(ownerstr); free(PSecurityD1); free(PSecurityD2); ret1: CloseHandle(hFile); return ret; }

    Read the article

  • Linking Post Title to Specific Page ID

    - by ThatMacLad
    I've created a form to update my websites homepage with content but I wanted to know how I could set it up so that a posts title links to a specific post ID. I'd also like to add a Read More link that directs anybody reading the blog to the correct post. Here is my PHP code: <html> <head> <title>Blog Name</title> </head> <body> <?php mysql_connect ('localhost', 'root', 'root') ; mysql_select_db ('tmlblog'); $sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5"; $result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error()); while($row = mysql_fetch_array($result)) { $date = date("l F d Y", $row['timestamp']); $title = stripslashes($row['title']); $entry = stripslashes($row['entry']); $password = $row['password']; $id = $row['id']; if ($password == 1) { echo "<p><strong>" . $title . "</strong></p>"; printf("<p>This is a password protected entry. If you have a password, log in below.</p>"); printf("<form method=\"post\" action=\"post.php?id=%s\"><p><strong><label for=\"username\">Username:</label></strong><br /><input type=\"text\" name=\"username\" id=\"username\" /></p><p><strong><label for=\"pass\">Password:</label></strong><br /><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form>",$id); print "<hr />"; } else { ?> <p><strong><?php echo $title; ?></strong><br /><br /> <?php echo $entry; ?><br /><br /> Posted on <?php echo $date; ?> <hr /></p> <?php } } ?> </body> </html> Thanks for any help. I really appreciate any input!

    Read the article

  • What can you do in C without "std" includes? Are they part of "C," or just libraries?

    - by Chris Cooper
    I apologize if this is a subjective or repeated question. It's sort of awkward to search for, so I wasn't sure what terms to include. What I'd like to know is what the basic foundation tools/functions are in C when you don't include standard libraries like stdio and stdlib. What could I do if there's no printf(), fopen(), etc? Also, are those libraries technically part of the "C" language, or are they just very useful and effectively essential libraries?

    Read the article

  • non blocking TCP-acceptor not reading from socket

    - by Abruzzo Forte e Gentile
    I have the code below implementing a NON-Blocking TCP acceptor. Clients are able to connect without any problem and the writing seems occurring as well, but the acceptor doesn't read anything from the socket and the call to read() blocks indefinitely. Am I using some wrong setting for the acceptor? Kind Regards AFG int main(){ create_programming_socket(); poll_programming_connect(); while(1){ poll_programming_read(); } } int create_programming_socket(){ int cnt = 0; p_listen_socket = socket( AF_INET, SOCK_STREAM, 0 ); if( p_listen_socket < 0 ){ return 1; } int flags = fcntl( p_listen_socket, F_GETFL, 0 ); if( fcntl( p_listen_socket, F_SETFL, flags | O_NONBLOCK ) == -1 ){ return 1; } bzero( (char*)&p_serv_addr, sizeof(p_serv_addr) ); p_serv_addr.sin_family = AF_INET; p_serv_addr.sin_addr.s_addr = INADDR_ANY; p_serv_addr.sin_port = htons( p_port ); if( bind( p_listen_socket, (struct sockaddr*)&p_serv_addr , sizeof(p_serv_addr) ) < 0 ) { return 1; } listen( p_listen_socket, 5 ); return 0; } int poll_programming_connect(){ int retval = 0; static socklen_t p_clilen = sizeof(p_cli_addr); int res = accept( p_listen_socket, (struct sockaddr*)&p_cli_addr, &p_clilen ); if( res > 0 ){ p_conn_socket = res; int flags = fcntl( p_conn_socket, F_GETFL, 0 ); if( fcntl( p_conn_socket, F_SETFL, flags | O_NONBLOCK ) == -1 ){ retval = 1; }else{ p_connected = true; } }else if( res == -1 && ( errno == EWOULDBLOCK || errno == EAGAIN ) ) { //printf( "poll_sock(): accept(c_listen_socket) would block\n"); }else{ retval = 1; } return retval; } int poll_programming_read(){ int retval = 0; bzero( p_buffer, 256 ); int numbytes = read( p_conn_socket, p_buffer, 255 ); if( numbytes > 0 ) { fprintf( stderr, "poll_sock(): read() read %d bytes\n", numbytes ); pkt_struct2_t tx_buf; int fred; int i; } else if( numbytes == -1 && ( errno == EWOULDBLOCK || errno == EAGAIN ) ) { //printf( "poll_sock(): read() would block\n"); } else { close( p_conn_socket ); p_connected = false; retval = 1; } return retval; }

    Read the article

  • why is strtof is always evaluating to HUGE_VAL?

    - by bstullkid
    What could be the issue here? It doesn't matter what number I choose for str, it is always 26815615859885194199148049996411692254958731641184786755447122887443528060147093953603748596333806855380063716372972101707507765623893139892867298012168192.00 char *str = "2.6"; printf("%f\n", strtof(str, (char**)NULL)); //prints 26815615859885194199148049996411692254958731641184786755447122887443528060147093953603748596333806855380063716372972101707507765623893139892867298012168192.00

    Read the article

  • Udp server sending only 0 bytes of data

    - by mawia
    Hi all, This is a simple Udp server.I am trying to transmit data to some clients,but unfortunetly it is unable to transmit data.Though send is running quite successfully but it is returning with a return value meaning it has send nothing.On the client they are receiving but again obviously,zero bytes. void* UdpServerStreamToClients(void *fileToServe) { int sockfd,n=0,k; struct sockaddr_in servaddr,cliaddr; socklen_t len; char dataToSend[1000]; sockfd=socket(AF_INET,SOCK_DGRAM,0); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr=htonl(INADDR_ANY); servaddr.sin_port=htons(32000); bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)); FILE *fp; if((fp=fopen((char*)fileToServe,"r"))==NULL) { printf("can not open file "); perror("fopen"); exit(1); } int dataRead=1; while(dataRead) { len = sizeof(cliaddr); if((dataRead=fread(dataToSend,1,500,fp))<0) { perror("fread"); exit(1); } //sleep(2); for(list<clientInfo>::iterator it=clients.begin();it!=clients.end();it++) { cliaddr.sin_family = AF_INET; inet_aton(inet_ntoa(it->addr.sin_addr),&cliaddr.sin_addr); cliaddr.sin_port = htons(it->udp_port); n=sendto(sockfd,dataToSend,sizeof(dataToSend),0,(struct sockaddr *)&cliaddr,len); cout<<"number of bytes send by udp: "<< n << endl; printf("SEND this message %d : %s to %s :%d \n",n,dataToSend,inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port)); } } } I am checking the value of sizeof(dataTosend) and it is pretty much as expected ie thousand ie the size of buffer. Are you people seeing some possible flaw in it. All of the help in this regard will be appreciated. Thanks!

    Read the article

  • Write to text file using ArrayList

    - by Ugochukwutubelum Chiemenam
    The program is basically about reading from a text file, storing the current data into an ArrayList, then writing data (from user input) into the same text file. Kindly let me know where I am going wrong in this sub-part? The data inside the text file is as follows: abc t1 1900 xyz t2 1700 The compiler is showing an error at the line output.format("%s%s%s%n", public class justTesting { private Scanner input; private Formatter output; private ArrayList<Student> tk = new ArrayList<Student>(); public static void main(String[] args) { justTesting app = new justTesting(); app.create(); app.writeToFile(); } public void create() { Text entry = new Text(); Scanner input = new Scanner(System.in); System.out.printf("%s\n", "Please enter your name, ID, and year: "); while (input.hasNext()) { try { entry.setName(input.next()); entry.setTelNumber(input.next()); entry.setDOB(input.next()); for (int i = 0; i < tk.size(); i++) { output.format("%s%s%s%n", tk.get(i).getName(), tk.get(i) .getTelNumber(), tk.get(i).getDOB()); } } catch (FormatterClosedException fce) { System.err.println("Error writing to file."); return; } catch (NoSuchElementException nsee) { System.err.println("Invalid input. Try again: "); input.nextLine(); } System.out.printf("%s\n", "Please enter your name, ID, and year: "); } } public void writeToFile() { try { output = new Formatter("testing.txt"); } catch (SecurityException se) { System.err .println("You do not have write access permission to this file."); System.exit(1); } catch (FileNotFoundException fnfe) { System.err.println("Error opening or creating file."); System.exit(1); } } }

    Read the article

< Previous Page | 42 43 44 45 46 47 48 49 50 51 52 53  | Next Page >