Sponsored Content
Full Discussion: Why I don't get any output?
Top Forums Programming Why I don't get any output? Post 302089067 by Sharmin on Saturday 16th of September 2006 01:50:23 PM
Old 09-16-2006
Why I don't get any output?

Hello,

I am very new in writing low level programming in C. I am trying to get an output in Linux 2.6.17.6 gentoo platform, but I don't get any output.

I am trying to do the following:

I am trying to scan a word and print its content at the standard output by using sscanf and printf.

I am trying to read the cpuinfo at the /proc directory, which looks like as following, and then, I am trying to print the highlighted string.

cat cpuinfo

processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Celeron(R) CPU 2.60GHz

stepping : 9
cpu MHz : 2591.654
cache size : 128 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe up cid xtpr
bogomips : 5189.98

But, I can only print the model name but cannot print its concent.

My C file looks as below.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

main(int argc,char **argv) {
char mybuf[4256];
char vernum[116];
int fd;
int errs;
int count;

if (argc != 2) {
printf("Bad command line argument\n");
exit(-1);
}
if ((fd = open (argv[1],O_RDONLY))< 0){
perror("Bad open");
exit(-1);
}
while ((count = read(fd, &mybuf[0], sizeof(mybuf))) > 0) {
count = read(fd,&mybuf[0],sizeof(mybuf));
sscanf(&mybuf[0],"model name %s",&vernum[0]);
printf("The model name is:%s\n", &vernum[0]);
}
if(count < 0) {
perror ("Bad read");
exit (-1);
}
}

Please tell me what I shouls fix at sccaf( ) and at the printf( ) method. I tried a lot by reading the man page to read new line or empty space or \t and by putting %c or *. But I never cannot print anything after model name.

If you need, you can see the file "cpuinfo" at /proc directory. Type cd /proc
then cat cpuinfo.


Please help me; I am here for help as it is a help forum for new and unexperienced like me.

Please tell me what to do in the code and what to write....so that I can print the whole string "model name : Intel(R) Celeron(R) CPU 2.60GHz"

Thank you.
Sharmin
Smilie

Last edited by Sharmin; 09-16-2006 at 02:52 PM.. Reason: Editing wording
 

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Don't allow to editing !!!

Hi All, Assume that there is file1 file,userA and userB have got read,write and execute permission for file1. when userA open file1, userB cant change(write,editing file etc...) content of file1. after userA exit of file1 , userB can change(write, editing file etc..). Shortly i want... (1 Reply)
Discussion started by: temhem
1 Replies

2. Programming

std::cout and gfortran print*, don't output to the screen

I am not sure where to post this other than here. I am trying to figure out why an app gives different output when compiled under Ubuntu 10.10 and CentOS 5.5. I am pretty sure that the issue is that the Cent version has gcc 4.1 installed, while Ubuntu has gcc 4.4. I am trying to print from some... (20 Replies)
Discussion started by: LMHmedchem
20 Replies

3. Shell Programming and Scripting

AIX -/usr/bin/expect shows output Don't know why.

Hi, I have been programming with the expect program for a while now and have create a series of menu driven checks for the operations team. One thing I have noticed is that I call a remote script and pass parameters and this is display on the screen....for example. Within the script ... (0 Replies)
Discussion started by: yakky
0 Replies

4. Shell Programming and Scripting

Find command don't output anything, but file is there

Please if You can help me debug why nothing is found by this command? # echo "Zeus Robot" >> /home/vps/190/test # cat /home/vps/190/test Zeus Robot # find /home/vps -type f -mtime 2 -size -1000k -exec grep -l "Zeus Robot" {} \; >> out # cat out # cat /home/vps/190/test Zeus Robot Why... (6 Replies)
Discussion started by: postcd
6 Replies

5. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies
BF-model-EDITOR(1)					      General Commands Manual						BF-model-EDITOR(1)

NAME
bf-model-editor -- The model editor for the Bear Engine. SYNOPSIS
bf-model-editor [-h] [--log-concise] [--log-file=file] [--log-level=string] [--log-uniq] [-c] [-u] file(s) ... DESCRIPTION
This program is the model editor for the Bear Engine. This is a part of the Bear Factory. OPTIONS
The following options can be passed to the program: -c, --compile Compile the files and exit. -h, --help Show summary of options. --log-file=file Write log output in "file". --log-level=string Output log messages up to a given level, among "error", "warning" and "verbose". -u, --update Open and save the model files. -v, --version Print the version of the editor and exit. SEE ALSO
running-bear(6), bf-animation-editor(1), bf-level-editor(1) AUTHOR
This manual page was written by Julien Jorge julien.jorge@gamned.org. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. BF-model-EDITOR(1)
All times are GMT -4. The time now is 01:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy