Monday, May 24, 2010

How do I communicate over serial with an ARM processor in C?

I'm using a TS7200 found at: http://www.embeddedarm.com/epc/ts7200-sp...





All I've ever done with C is software, no hardware interfacing. I'll be communicating to a Garmin 301 Geko GPS on com port 1 in linux. All it has to do is to read data, not transmit.





I know that I wont get exactly what I need, but I can't find much on the internet to help me. Does anyone have a good site to look at?





Thanks for your help,


Brandon

How do I communicate over serial with an ARM processor in C?
I would go to a more experineced place on the internet then Yahoo! forum for C help. try developer fourms for linux only


Am trying to write java code to read n write bits at the parallel port of a computer.how can i do it on linux?

the motive is to be able to read and write bits at the parallel port using a JAVA application on a linux platform... i need to know how to get the permission ant control from the OS, i am able to do it in C using ioperm....

Am trying to write java code to read n write bits at the parallel port of a computer.how can i do it on linux?
Or may be you can contact a java expert. Check websites like http://getafreelnacer.com/
Reply:Mr. Rai try this link for PARALLEL PORT ADDRESSES








http://www.captain.at/parallel-port.php





IBM site





http://www.ibm.com/developerworks/java/j...





HOW TO CD-Writing





http://www.faqs.org/docs/Linux-HOWTO/CD-...

dracaena

Build a hierarchical tree, without using DOM,schema, and sax using expat parser and c?

I've been experimenting with the jclark's expat parser. I compiled it on linux, and it works just great. However, finding tags and data by implementing the callback functions in c language is cumbersome. Has anybody written code that uses the expat callback's in such a way as to build a hierarchical tree, without using DOM,schema, and sax, that can be traversed.My purpose, just enough to traverse branches and find leafs of a xml documents without using DOM, schema, and sax, and i also want help regarding how to convert a xml document to a hierachical tree which contains tags values. thanks

Build a hierarchical tree, without using DOM,schema, and sax using expat parser and c?
but what you're describing more or less is the same like a DOM, right? a hierarchical tree of xml data.





have a look at the link below, it's the Simple C Expat Wrapper which builds a DOM-like structure, maybe it can help you.


I am working on my first useful program in c! this is how far I got with it and I got stuck?

It is a calculator! And I am trying to make it give me a message when you input letters instead of numbers!








How would u write the whole program using functions????





this is the code! i use linux and the gcc compiler














#include %26lt;stdio.h%26gt;





int main( )


{


int z;


int x;





printf( "This is my first useful program ever created in C" );


printf( "\n" );


printf( "\n" );


printf( "Note that this calculator will subtract and divide the first integer by the second one" );


printf( "\n" );


printf( "\n" );





printf( "Input your first integer to be calculated:" );


scanf( "%d", %26amp;z);





printf( "Please input the second one:" );


scanf( "%d", %26amp;x);





printf ( "Added: %d \n", z + x );


printf ( "Subtracted: %d \n", z - x );


printf ( "Multiplied: %d \n", z * x );


printf ( "Divided: %d \n", z / x );


}

I am working on my first useful program in c! this is how far I got with it and I got stuck?
Two ways.





Check the return type. Look at http://www.cplusplus.com/reference/clibr... (scanf). It returns an int, which actually means something. Check if that integer matches EOF, and if it does, you know it failed to read in the input.





Only a beginner is excused from not checking for errors. Understand how the library functions work. If they set an error bit or return something on error, check for that.





The other way is to use fgets and strtol. Use fgets to take an input into a string. Then attempt to convert using strtol.
Reply:You will find lots of useful c programming sourcecode @ www.easytutor.2ya.com
Reply:Well, I'm not going to write the code for you--but one way you can figure out if inputs are characters or numbers, is to check its ascii code. If the ascii code of the input from the user is not that of a number, than return an error message.

morning glory

How to create our own library file and header file from c (OS is windows xp)?

I want to know how to create our own library file and header file in c.





i use turbo C and the os is windows xp.


i could find the command equivalent of 'ar' command in Linux (archieve command) same in Windowz xp





thanks

How to create our own library file and header file from c (OS is windows xp)?
hi,





first you can create header file by ( .h ) extension.for example triq.h in this file you can write what (functions) you wants in the header file.





second you can store this ( .h ) file extension in to header files location.





then crate c program and include this header file.thats all..bye
Reply:create files





bob.h


bob.c





In bob.c put:





#include "pathto\bob.h"





your c code here


Which is harder to learn Java or C++ ?

I would rate myself as a beginner/intermediate VB.NET programmer - very good at scripting with VBScript.





So I haven't really touched on either Java or C++ or any "real" programming since I personally consider VB.NET cheating as you're really just drawing and filling in the gaps with code you can search for online!!!!


Could someone recommend to me one or the other ? my destination platform would be both Linux and Windows.





Thanks in advance !!!!

Which is harder to learn Java or C++ ?
As far as object orientated programming goes, the fundamentals are very similar. I learned c++ first, and found it harder to learn that java. But that could have been because it was my first language.





What I am certain of though, is that java is much more sought after now than C++. So it may be more beneficial for you to learn that first.





As far as compilers go, for just starting off in object orientated programming, then you might want to go for a compiler called "bluej". It's a very simple GUI interface, to get you used to classes.





After that I would move on to netBeans IDE 6.0....and stick with it.
Reply:As long as you're comfortable with object orientated programming I think you'd find both languages about the same to learn.





In terms of jobs (if that's what you're thinking of), people seem to want Java programmers more than C++ programmers nowadays, and C# is an even better bet.
Reply:C++ is harder to learn, because most of the low level things found in C++ like pointers, garbage collection are handled automatically in java. Java programs can run on any platform that has a JVM (java virtual machine).
Reply:I'd say java because the polarity of the script certification does not interface with the trajectory of the triple mainframe processor.


Which is the best windows based c++ compiler?

I have been using g++ compiler that is available on linux. now I am switching to windows. And I want to do programming in the same way I used to do on g++. suggest me windows based c++ compiler that has this feature.

Which is the best windows based c++ compiler?
I have no experience in development on Linux platform.


To develop on Windows, i have used Microsoft Visual C++ (Most recommended for professional development).


Another recommended compiler is using the Borland C++ Builder.
Reply:Visual Studio seems to be the best on the windows platform. Borland's IDE was okay aswell, but i'm not sure if they still ship and or support it.


How do I practice C programming at home?

Hi,





I'm taking a basic programming class since I'm an electrical engineering undergrad. I have programming classes every Monday and Wednesday, however, for the type of learner that I am, I need to do a lot of practice. I asked my professor how I could work at home, but instead, he suggested that I just come into the lab to work my problems out. I live pretty far from school so I don't really want to do that. I mean, it's regular C language, so I'm positive I could do it on my laptop running XP media center '05.





I don't know the info you need to answer the question, but here are a few facts.





-We're using the OS Red Hat Linux


-We use text editor to program


-We use something called terminal that looks a lot like MS-DOS





I've read that I can use notepad and MS-DOS to do the same things, but I couldn't figure it out. I hope I gave enough info. I'll add on more if you do need to know some extra.

How do I practice C programming at home?
In linux


vi a.c


write code


type gcc a.c


run a.out


in windows


download turbo c compiler and use it to compile the code.
Reply:The Link below tells you how to write an ANSI C program using C++ in 2005 Visual Studio.
Reply:There will be some differences in the libraries available to a Windows Programmer and a Unix/Linux programmer. For example, Windows does not have a "fork()" function (as far as I know). Unix/Linux does not have a conio.h library.





I would suggest trying an install of Linux on your home computer as a dual boot system. While there are very good C/C++ compilers available for Windows, Unix/Linux is pretty much the standard for techies. If you're going into engineering, you will probably need to learn Unix in one form or another.





Also, Linux and Unix are pretty good about following standards. The Gnu compiler is pretty universal on all Unix like systems, like Linux and Mac OSX.





Any Linux distro will do. For a newbie, try using Ubuntu or Kubuntu. You will need to select development packages during the installation. You can use a fancy IDE like eclipse or Kdevelop. However I personally prefer to use EMACS while some folks I know prefer to use VI. In any case, these editors are geared more for programmers.





The Idea of using Notepad to edit code sounds excruciating. Notepad is not meant for programming. It doesn't have a C mode that automatically indents your code for readability. It doesn't have macros that make programming easier. It is simply a very bare bones editor.





Another option is to download the Cygwin toolkit. Cygwin is a port of the Gnu compiler for Windows and it includes a bunch of standard Unix libraries ported to Windows. It also includes a bash shell (the thing that's like the MSDOS prompt).





Learn the shell. Bash is much more powerful than the DOS shell and if you go into engineering and programming, you'll find it handy to know. I don't know how Windows programmers are able to program without it.





For an editor, I personally recommend EMACS. It has been ported to Windows. But for any really large projects, you'll want an IDE like eclipse.





Whatever you do, do NOT go out and buy Microsoft Visual C++ or C#. They are NOT standard and are not easily ported to Unix (where your schoolwork will be graded). As I said, as an engineer, Unix will probably be a requirement.
Reply:All you need to write C at home is a text editor and a compiler. The text editor can be as simple as notepad or as slick as the Eclipse integrated development environment. For a compiler, google 'c compiler' and you'll get a whole list of freebies.





Something else you might be interested in would be Microsoft's Visual C# (pronounced "C Sharp"). You can download Visual C# Express for free from their website, which will include a compiler and -- in my opinion -- the slickest of all integrated development environments, Microsoft Visual Studios 2008. From there, you can build Windows applications, web applications, XAML browser applications, web services -- all kinds of stuff.





Best of luck.








Edit -- to "Mike D"...





I find it hilarious that a professional programmer -- who uses EMACS, no less --can't figure out know how a Windows programmer can function without BAsh .





See, to me, one look at BAsh and emacs makes me have flashbacks from when I was programming Pascal on Unisys ICON machines in a QNX environment back in high school... Kinda makes me want to put a gun in my mouth, frankly.





I mean, say what you will about Microsoft, but Visual Studio sets the gold standard for integrated development. Open your mind, give it a tumble, and see what it's like writing code in the 21st century. You might just like it.

geranium

How do I read a BYTE [not a sector] from a CD, preferably in C++?

I do apologize for having to include this in my question, but because the programming section is usually plagued full of slackers, pranksters, embeciles, and just plain ignorant individuals that interfere with those of us that wish to use this sub-site as a learning tool, it must be included: Please READ the darn question before you answer it. Please give an INTELLIGENT answer, not Huh? wot? I dunno, etc. ... Please PAY attention Do not give me code for VB5 under WinNT, DJCPP, or GCC on Linux, when all you had to DO was READ the whole question to realize I do not want that particular information. Thank you all for letting me speak my piece. Now on to the rest of myt question. I can use code in VC6, Visual C++ 2005, and Visual C# 2005. Managed / .NET is acceptable as well. I can use code for any Win32 OS. However, I do NOT do VB6, VB.NET, .VBS, Linux or any code developed for a Non-Microsoft OS. Thanks for all the help.

How do I read a BYTE [not a sector] from a CD, preferably in C++?
Hmmm, I never tried that, but assuming the byte is in a known file, I would think you could just open the file (same as on your hard drive), and read it out as characters. You would most likely have to open it as read (not write or read/write). Thats what I would try first.
Reply:It really won't matter which language you use, you are probably going to have to do a lot of low level OS interfacing, because reading at that level potentially violates a lot of OS protections that have been put in place to keep random programs from reading and writing random bytes to random positions your IO devices. Its just like reading from the 1537614th byte from your NTFS filesystem... you're supposed to be interfacing with the filesystem at the conceptual filesystem level, not the byte level, and its a good thing that most programs cannot.





BTW, VB.NET is easily translated to C# so even if you had a VB.NET solution, you probably could find something that would automatically translate it to C#. But I really doubt you'd find either.





CD's, Hard disks, etc, all read in blocks of data at one time so, like G. Whilikers said, even if you read in one byte, at some place in your memory the CD reader has read in the whole 512 bytes... so if you have code to read in the sector, the're really no other way to do it. Just pick the specific byte you need from that sector block.
Reply:Either find a way to treat the disk as an i/o stream, or grit your teeth and read the sector then pick up the byte you want. Even if you had a getSpecificByteFromCD() function available, underneath it's going to be reading the whole sector behind your back anyway.


Best resource for learning C++ for a 15 year old?

I have learned the basics of Visual Basic, and PHP(Html/CSS Included) and little of Mysql.





Usually when I try and learn C++, I give up way to early because I never get to do the things I want to do. Write GUI, Media Apps, etc... I plan on developing for Linux with KDE.

Best resource for learning C++ for a 15 year old?
Try checking out your local book store for any books on it. Alot of times they will have a CD included with a compiler so you can run some test programs. Usually in the book they will have some example programs for you to build upon.
Reply:AP Computer Science
Reply:I know what to try.
Reply:Take a class.
Reply:See if they have C++ for Dummies at your library.
Reply:There are alot of resources out there. My favorite is http://www.planet-source-code.com


Why does the following C code give segmentation fault?

#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


int main()


{


char *p="Hello";


printf("%s\n",p);


printf("%c\n",*p);


*(p)='A'; /*Replace the first letter with 'A'*/


printf("%s\n",p);


return 0;


}








I am using Linux operating system. In windows probably it will not give a segmentation fault.

Why does the following C code give segmentation fault?
Please see http://c-faq.com/decl/strlitinit.htmll .





You're creating a constant string literal, and then trying to modify it. Effectively, you're trying to write over read-only memory, and this is why a segfault occurs.





You could use Windows if you suffer from the "blame Linux" mentality. You'll get a segfault anyway, though.
Reply:To be able to manipulate bytes using a pointer, try using malloc to allocate a block of memory.


char *p = malloc(6);


strcpy(p, "Hello"); // copy string with trailing \0


*p = 'A';





The code you are using points p to a string in a constant table, and the program cannot write to the address.
Reply:As another person explained, you're replacing the


contents of the literal string "Hello", which the


compiler implementation is allowed (but not required)


to place into a read-only memory segment.





For example, on Solaris using the Sun compiler, this


does not cause a segmentation violation by default.


However, if you compile with the "-xstrconst" option


(which puts literal constants in read-only memory),


then of course, it does. The point is that it will


vary from platform to platform.
Reply:Don't use char *p="Hello";





Use





unsigned char p[] = "Hello";





#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


int main()


{


unsigned char p[]="Hello";


printf("%s\n",p);


printf("%c\n",p[0]);


p[0]='A'; /*Replace the first letter with 'A'*/


printf("%s\n",p);


return 0;


}





The static allocations by the complier are just that "static". For even more fun, compile your "broken" program with full optimization. You'll get no errors and of course no "Aello". The compiler optimizes out the write to read-only segments.


Need help with a c program?

I'm programming a bot to connect to IRC. I'm fairly new at C, and I need to know efficient ways to keep the program from exiting at the end of the main function. As of now, the bot connects and the programme ends, how do I keep it running so that the bot will stay there and I can move on to my next challenge of responding to PINGs





this is what I have


(very dry because I'm trying to make it work before I try new stuff)





if (connect(sockdesc, (struct sockaddr *)%26amp;their_addr,


sizeof their_addr) == -1) {


perror("connect");


exit(1);


}


char *connectreg="NICK test\r\nUSER testbot test test :My bot\r\n";


len = strlen(connectreg);


send(sockdesc, connectreg, len, 0);


return 0;


}





I need it to keep running so that I can start responding to PINGs after the send call.





My main goal as of now is to make it idle on the server, then I'm going to clean up the code a bit.





PS: I'm compiling under a linux system.

Need help with a c program?
You should put it in a while loop, i'm not familiar with C socket but Java socket. And then put a read from the socket stream there, the read will basically wait until there is an input from the remote side.


This is my pseudo code for this





send start signal to server





while(true)


{


readSignal from Server


process Signal


switch (signal)


case signal1 : handle and send proper signal back to server


case signal2 : handle and send proper signal back to server


..etc


}

sweet pea

Is fwrite in C blocking call?

Is fwrite in C blocking call from the app point of view? For example, if NFS is used as i/o, will the fwrite to a file residing on NFS mounted to the Linux be blocking?

Is fwrite in C blocking call?
yes, fwrite() is a blocking call - your program will not return from it while it is being processed.





Non-blocking calls only exist in programming environments with native threads, such as Windows. They do not really exist in UNIX. On Unix, non-blocking I/O within the same process is achieved using other tricks, such as select ( http://www.scit.wlv.ac.uk/cgi-bin/mansec... ).





Non-blocking equivalent of fwrite() on Windows is WriteFileEx():


http://msdn2.microsoft.com/en-us/library...


Which programming language (other than C++ and Visual Basic) is suitable to develop CD/DVD burning software?

In the future, after graduated, I plan to develop an open source CD/DVD burning software which have all the following features:





1) Burn: Data CD/DVD, Video CD (VCD), DVD video, Audio CD. if possible, include Blu-ray disc.





2) Convert: all video files to VCD/DVD format, Audio files to MP3 format.





3) Backup: Any files, or entire computer.





4) Copy: disc to disc, disc to image (example: ISO), image to disc).





5) Edit: video and audio files





6) Supported operating system: Windows, Linux, Mac





7) Price: always free, including the source code.





I don't want to use C++ and Visual Basic

Which programming language (other than C++ and Visual Basic) is suitable to develop CD/DVD burning software?
Probably you would not write all this functionality but reuse libraries for the majority of it.





Due to this, you are more concentrating on the interface. You could look at c# but its mostly windows only (can work on Linux, but limited)





Java is portable and you can use c libraries, but the interfaces tend to suck a bit in my opinion on java apps.





You could use c/++ but I don't think you need to go to so much trouble when your main task is the interface.
Reply:There are a lot of languages that could do this but I think you are looking for a powerful language that easy and reduces the development cost. I think you should take a close look into C#.NET 2005 Express Edition. It's free and surprisingly powerful. You are working with audio and video, and this means you want your software to function at maximum speed. C# offers a number of unsafe execution techniques that could do the job. Beside that it is a .NET language, and this means easy development and debugging platform.


My computer c drive missing....help?

i installed partition magic to seperate my two drive to install linux andwindows vista ultimate. i had already ulitmate. but after insatlling partion magic it says your disk drive is an error, so i fixed it and after that i tried to uninstall it, when i tried to uninstall from control panel, computer shut down. and then i restarted it says windows cannot be loaded.


i tried to install fresh copy ultimate but it says ur c drive is formatted, and that time i dont have any partition magic software to do it, then i tried to restore dell restore from d drive which is only available. but after few seconds of formatting it crashed as well. so now i cannot access my system.





so guys i m in big trouble. i want to restore all my data which software i should buy/download? or is there any option to get those data ? and if any company does it near north london?





thnak you

My computer c drive missing....help?
As far as i think -FORGET your data.Now what you can do is run fdisk and make new partitions and format them or install xp directly and make new partitions and reformat.
Reply:i think unistall data recovery software may work in this case
Reply:Use your Vista install disk and delete your partition.


Don't go any further or format if you are going to keep Windows Xp.


Put the Xp disk in and let install a fresh copy.


If you want Vista, go ahead and put up a new partition, a large one, 80% of your total disk size at least and let it do it's thing.


"lex.yy.c"?

In my college days I have written programs which has "lex.yy.c" in it.


Now i want that language again to do some programming


what was that?


how can i get that compiler again?


is there a site to download that?


will that compiler run in windows?


do i have to install linux for this?


I googled to get : http://en.wikipedia.org/wiki/Lex_program...


Sounds very familiar.


P.S: I studied this on 6th sem of my engineering.


Computer science engineering Cochin University, Kerala.


Help!

"lex.yy.c"?
Yes, this is Lex and it is Wonderful, but in the beginning a little bit difficult.





Lex is a Lexical Analyzer, you can use it in several way, one that should be most used, is to convert a sequence of characters in your C source code into a sequence of tokens.





In this way you can, for example, crate your custom Makefile that compile on different platform and different operating systems.





To use it you need to read and read and read and try it.





This http://gnuwin32.sourceforge.net/packages... you can use on Windows, but I advice you to follow the links inside the wiki that you posted to understand clearly what are Lexical Analizer and how to use them

rose

Anyone know of a good c++ compiler?

hey i was thinking of getting back into c++ and i was wondering what a good compiler would be? and i know about linux compilers but i kinda dont have enough space for 2 operating systems again i only have 20 gigs and i want to keep it simple use it on windows anyone know of a good one thanks in advance =)

Anyone know of a good c++ compiler?
windows have a good one. This is the link http://msdn2.microsoft.com/en-us/visualc...


How to use IPC here (C++)?

Lets say X is a shell command that will get you into X-shell upon execution. There's a command, a module, Y that can be run only in X-shell. How can I run Y from a C++ code? I need to somehow tell my app that the environment it'll be dealing with will be X-shell and not the Linux shell. I haven't dealt with a case like that before and don't know how to incorporate IPC here. Would I take X-shell as the parent process and the spawned child as module Y? Not sure... I should point out that it's not possible to do something like "X-shell -c Y"; first X-shell has to be executed. Once in the X-shell environment, now Y can be called.





A word of wisdom is appreciated.

How to use IPC here (C++)?
Good question. If I remember correctly, can't you use one of the flavors of execve(...) to execute a script that puts you in the X-shell before running the Y command that needs to be run in this X-shell?





...


(in your C++ code)





execve("/bin/example/myscript",...)





...





/bin/example/myscript looks like:





#/bin/X /* putting you in the X-shell */





Y-command /* running the actuall Y command here */








Any way, this is off the top of my head but maybe it'll help a little bit.


Just how possible is it to make a command line hex editor for Linux?

I am very curious as to experimenting with these programs, and I have downloaded a graphical one named KHexEdit. I am using a Linux computer and am wondering as to how one could be made to work in the terminal. For example, I am just looking for the basic program without any GUI so I can learn how to make one. If anyone has any help on how to make one, please explain. I would also appreciate it if you could explain how to program one in C, if you can tell me. Otherwise, any way to make one is fine.

Just how possible is it to make a command line hex editor for Linux?
If you are a skilled enough programmer, probably not too hard. If you don't know file structures, you don't know programming, and you don't know how to use google to find such information - lotsa luck! You will need it!
Reply:Why would you want to make something that already exist?


C++ question; how do you get your program to read inputs from a txt file?

I know that it can be done in the Linux terminal, and using the Cygwin environment for WinXP. All the text file contains are numbers (type double) separated by spaces.





Problem is that Cygwin doesnt work too well on my system.


How do I make it happen on BloodShed Dev-C++ ?





I am a first year Engg. student with no prior programming experience, so I would appreciate if you answered in plain dumbass. Thanks in advance.

C++ question; how do you get your program to read inputs from a txt file?
I have no idea what role Linux or Cygwin plays in your question. You can open and read from a text file in a portable way (i.e. it doesn't matter if you are on Windows, Mac, Linux, BSD, etc.).





I'm not sure where to start explaining. So instead, I'll point you to tutorials, as I have a sinking feeling you haven't done much reading.





http://www.cprogramming.com/tutorial.htm...





Just go through the C++ tutorials please. If you don't understand a specific portion, ask a specific question. Rather than "how do I do file input".





(The answer is open up the file with an fstream. Then acquire each line in one of several ways. Either cin each token on the line, or use getline and break down the line by spaces).
Reply:You can use the ifstream class found in fstream.h.





ifstream input("file.txt");





you can now use input just like you use cin, except you'll be reading a file instead of keyboard input.

flowering plum