0
votes
3answers
69 views

Review: Compare two Anagrams words in C

A simple attempt by me to test whether two words are anagrams or not. Here is the code: #include <stdio.h> #include <ctype.h> #define CH_LEN 15 #define N 26 int main(void) { char ...
1
vote
2answers
127 views

Random Sentences code review

This program use random number generator to create sentences. It prints 20 sentences randomly. Here is the code: #include <stdio.h> #include <string.h> #include <time.h> #include ...
1
vote
3answers
172 views

Reverse a string without <string.h> header function

I'm learning C from K.N. King book and just arrive at a question to reverse the words in a sentence. Here is the output: Enter a sentence: you can cage a swallow can't you? Reversal of sentence: ...
3
votes
1answer
66 views

Matching element of arrays on a condition

if node[i] and node[i+1] are present in the neighbor[i], then store the 'i' position of node and print the 'i' value of node. this is also done by reversing the node array(only) and same type of ...
3
votes
1answer
261 views

Magic Square in C (Beginner)

Still teaching myself C out of KN King's C Programming: Modern Approach. Actually pretty excited I go this problem solved in under 2 hours haha. I asked this over on Stack Overflow and it was ...
1
vote
1answer
144 views

first non-repeated character in a string in c

Write an efficient function to find the first non-repeated character in a string. For example, the first non-repeated character in "total" is 'o' and the first non-repeated character in "teeter" is ...
4
votes
2answers
101 views

Counting letters program. Notation and optimisation help

I am writing a program in C running on UNIX which counts the number of each letters in a input text file. For a file like this: The cat sat on the green mat The output would be like this: The ...
1
vote
2answers
180 views

Please help me debug this little C program on dynamic two-dimensional array?

I am a newbie here. I have written a little C program, which is to create a two-dimensional matrix. Here is the code: #include <stdio.h> #include <stdlib.h> int **CreatMatrix(int ...
1
vote
1answer
116 views

C arrays and loops optimization

I am writing a program for learning purposes that takes an input of a file structured similarly to: 13,22,13,14,31,22, 3, 1,12,10 11, 4,23, 7, 5, 1, 9,33,11,10 40,19,17,23, 2,43,35,21, 4,34 ...
5
votes
3answers
169 views

Devise an algorithm of complexity O(N) finding No of 1's from a 2 dimensional matrix[N][N] containing 1's and 0's

Assume a 2d [n][n] Matrix of 1's and 0's/ All the 1's in any row should come before 0's/The number of 1's in any row i should be atleast the no of 1's row (i+1). find a method and write a c program to ...
2
votes
1answer
598 views

RungeKutta method in C, pointers and arrays, everything handled correctly?

Now the program works. But is it correct? Sometimes it works in C anyway... :) Could I improve it somehow(not numerically, just C-wise)? I need to allocate the array as I do right? Since I am ...
1
vote
1answer
746 views

What value the rear and front counter of an Array implementation of Queue start with? -1 or 0 or 1?

Is there anything wrong with this implementation of Queue with array? I have started front = rear = -1. Some references tend to start front = 0 like this:enter link description here I think if ...
5
votes
2answers
367 views

Please review this C-style array class

I often use C API's in C++ that force me to use C-style arrays. I got sick of constantly using a dynamic vector with &vec[0], so I wrote this C-style array container. Please review and give ...
4
votes
3answers
6k views

What's the best method to initialize character array in C and why? [closed]

I have seen C strings initialized to empty string and a null character. char str[10] = ""; or char str[10] = {'\0'} I am just confused which one is the best practice and I would like to know if ...