Tagged Questions

C is a medium level general purpose compiled language.

learn more… | top users | synonyms

2
votes
2answers
34 views

Creating an 2D array using pointer/malloc, and then print it out [closed]

I am trying to write 2 functions, one to read the matrix (2D array) and other one to print it out. So far I have: /* Read a matrix: allocate space, read elements, return pointer. The number of ...
3
votes
0answers
35 views

Print all permutations with repetition of characters

Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order Examples: Input: AB ...
0
votes
1answer
57 views

Radix Sorting with using queue [closed]

I have been trying to finish a book, Problem Solving and Program Design in C. In that book, there is a chapter, Dynamic Data Structures. I have understood main parts of that chapter. But, I couldn't ...
-1
votes
0answers
31 views

socket programming, two way communication in C [closed]

I have a code in a C for simple server-client communication, I have managed to send data from client to server, but for only one line, I need to make this connection continued all the time and also I ...
9
votes
3answers
113 views

Reversing a linked list

I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
2
votes
2answers
75 views

A clean and efficient makefile for a simple c program

I have an instructor who is very stringent on makefiles only containing rules and dependencies that need to be included. The structure for the program is very basic. The requirement is to produce ...
2
votes
2answers
91 views

the number of connected component

Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, M(x1, y1) == -1 && M(x2, y2) == -1 && |x1-x2|+|y1-y2|=1 ...
0
votes
1answer
88 views

Finding the most common phrase in a list of sentences

I need to write code in C to find most common phrases in a file of sentences. Each sentence has only lower case English words and ends with a linebreak/endline. A phrase is defined as 3 ...
5
votes
2answers
105 views

reverse every word in a string(should handle space)

Examples: char test1[] = " "; char test2[] = " hello z"; char test3[] = "hello world "; char test4[] = "x y z "; Results: " " " olleh z" "olleh dlrow " "x ...
1
vote
0answers
46 views

RingBuffer in C

I am trying to get into C stuff, and I thought it would be a good idea to try and implement a circular buffer. I have defined my struct like this: typedef struct { int8_t* buffer; int8_t* ...
2
votes
3answers
196 views

C function with too many levels of indentation

I've written the following function. I did my best to make it simple, but it is still over 30 lines and has too much indentation caused by the series of ifs. Any suggestions make it easier to read ...
2
votes
0answers
35 views

Improving the efficiency of a depth-first search method for searching for all “superpalindromes” whose prime factors are all <=N?

A question was asked over at math.SE (here) about whether or not there are infinitely many superpalindromes. I'm going to rephrase the definition to a more suitable one for coding purposes: ...
1
vote
0answers
13 views

integer constant is too large for “long” type [migrated]

I am creating random integers with the following algorithm: int random; int i; for (i = 0; i < RANDOM_COUNT; i++) { random = (((int) rand() << 0) & 0x0000FFFFd) | ...
6
votes
4answers
136 views

How to improved and optimized my squeeze() function

I am currently reading The C Programming Language by Dennis Richie and Brian Kernighan, and I came to implement the function squeeze (s1, s2) as an exercise. squeeze() deletes each character in s1 ...
1
vote
1answer
68 views

How to improve this message buffering code

I think this code to parse a contrived message protocol with first byte data length followed by data is a little ugly. Has anyone got any suggestions on how to make more elegant and more robust? ...

1 2 3 4 5 17
15 30 50 per page