I read file, but in the end of file i get unknown symbols:
int main()
{
char *buffer, ch;
int i = 0, size;
FILE *fp = fopen("file.txt", "r");
if(!fp){
printf("File not found!\n");
exit(1);
}
fseek(fp, 0, SEEK_END);
size = ftell(fp);
printf("%...
I make this program ::
#include<stdio.h>
char *raw_input(char *msg);
main() {
char *s;
*s = *raw_input("Message Here Is: ");
printf("Return Done..");
printf(s);
}
char *raw_input(char *msg){
char *d;
printf("%s", msg);
scanf("%s",&d);
return d;
}
What this do is, it print my message and scan for input from the user, then pr...
Is it even possible to create an array of bits with more than 100000000 elements? If it is, how would I go about doing this? I know that for a char array I can do this:
char* array;
array = (char*)malloc(100000000 * sizeof(char));
If I was to declare the array by char array[100000000] then I would get a segmentation fault, since the m...
hi,
I have a problem in a C program of mine where after I use fread(), the file pointer goes to the end of the file sometimes.
I'll try to explain better - the code looks something like:
dummy = ftell(fp);
fread(&buf, sizeof(unsigned char), 8, fp);
dummy = ftell(fp);
where fp is a file pointer to an opened file (opened it with "w+", ...
when i read through source files of opensource projects i often come across some weird phrases in the comments
/*
@brief ......
@usage.....
@remarks....
@par....
*/
questions
1.What are they?(were not mentioned when i was learning c++)
2.Do they have any documentation(where)
...
How to write following statement in c using switch statement in c
int i = 10;
int j = 20;
if (i == 10 && j == 20)
{
Mymethod();
}
else if (i == 100 && j == 200)
{
Yourmethod();
}
else if (i == 1000 || j == 2000) // OR
{
Anymethod();
}
EDIT:
I have changed the last case from '...
OS: Linux, Language: pure C
I'm moving forward in learning C progpramming in general, and C programming under UNIX in a special case :D So, I detected a strange (as for me) behaviour of the printf() function after using a fork() call. Let's take a look at simple test program:
#include <stdio.h>
#include <system.h>
int main()
{
int...
Hi, I am using the Eclipse CDT and I have a goto label and a FILE definition after it and when I compile the project it gives me the error: Expression expected before FILE.
Thanks in advance,
Mr. Man
EDIT:
Ok, so this is what I get from the command line:
iOS.c: In function ‘main’:
iOS.c:45: error: expected expression before ‘FILE...
Hi,
Let's say I have the following content:
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
How do I search for dummy or dummy text in that string using C? Is there any easy way to do it or only with strong string manipulation? All I need is to search for it and return a Boolean with the result.
EDIT:
You ...
I would like to write a function which will read values from a text file and write them to variables. For example my file is:
mysql_server localhost
mysql_user root
mysql_passworg abcdefg
mysql_database testgenerator
log log.txt
username admin
password abcd
and I have the same variables as the first word in the line.
So how to make t...
I'm trying to create a child process in another process. I am writing both the programs in C language. First I write a dummy process which will be the child process. What it is doing is only to write a string on the screen. It works well on its own. Then I write another program which will be the parent process. However, I can't make it h...
You need to use division and remainder by 10. Consider this example:
163 divided by 10 is 16, remainder 3
16 divided by 10 is 1, remainder 6
1 divided by 10 is 0, remainder 1
You'll notice the remainder is always the last digit of the number that's being divided. How do I do this in C?
...
Say you have a variable n1 which will be the value of three digits entered
how can i then without knowing what exactly will be input split n1 into 3 seperate integers to do futher calculations with?
...
Hi SO,
I'm just trying out the allegro library, and here is the code which I've got so far:
#include <allegro.h>
int main(int argc, char *argv[]) {
allegro_init(); // initialize the allegro libraries
install_keyboard(); // initialize keyboard functions
set_color_depth(16); // set the color depth
set_gfx_mode(GFX_AUTO...
Hi,
Supposing I have this:
"foo bar 1 and foo bar 2"
How can I split it into:
foo bar 1
foo bar 2
?
I tried strtok() and strsep() but neither worked. They don't recognize "and" as delimiter, they recognize "a", "n" and "d" as delimiters.
Any function to help me with this or I'll have to split by the blank space and do some strin...
I am trying to read strings from a file that has each string on a new line but I think it reads a newline character once instead of a string and I don't know why. If I'm going about reading strings the wrong way please correct me.
i=0;
F1 = fopen("alg.txt", "r");
F2 = fopen("tul.txt", "w");
if(!feof(F1)) {
do{ //start sc...
I am testing the sending and receiving programs with the code as
The main() function is below:
#include "lib.h"
int fd;
int initport(int fd) {
struct termios options;
// Get the current options for the port...
tcgetattr(fd,
// Set the baud rates to 19200...
cfsetispeed(
cfsetospeed(
// Enable the receive...
The book Beginning Linux Programming (3rd ed) says
"Note that fread and fwrite are not recommended for use with structured data. Part of the problem is that files written with fwrite are potentially nonportable between different machines."
What does that mean exactly? What calls should I use if I want to write a portable structur...
I am doing a recursive program and I am getting an error about conflicting types:
void* buddyMalloc(int req_size)
{
// Do something here
return buddy_findout(original_index,req_size); // This is the recursive call
}
void *buddy_findout(int current_index,int req_size)
{
char *selected = NULL;
if(front!=NULL)
{
...
Background:
I'm new to Objective-C and I've never touched C before. I'm trying to include a C library in my iPhone/iPod Touch project and I could not successfully compile the library's source code using the included instructions, so I've resorted to including the .h and .c files in Xcode. The library is for Hebrew Dates and correspondin...