• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:17
CEST 06:17
KST 13:17
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Team TLMC #5 - Finalists & Open Tournaments2[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon10[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12
Community News
StarCraft II 5.0.15 PTR Patch Notes170BSL 2025 Warsaw LAN + Legends Showmatch2Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8
StarCraft 2
General
#1: Maru - Greatest Players of All Time StarCraft II 5.0.15 PTR Patch Notes SC4ALL: A North American StarCraft LAN Team TLMC #5 - Finalists & Open Tournaments Classic Games #3: Rogue vs Serral at BlizzCon
Tourneys
RSL: Revival, a new crowdfunded tournament series SC2's Safe House 2 - October 18 & 19 Stellar Fest KSL Week 80 StarCraft Evolution League (SC Evo Biweekly)
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
ASL ro8 Upper Bracket HYPE VIDEO Starcraft: Destruction expansion pack? StarCraft - Stratospace. Very rare expansion pack StarCraft Stellar Forces had bad maps BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Ro16 Group D SC4ALL $1,500 Open Bracket LAN BSL 2025 Warsaw LAN + Legends Showmatch [ASL20] Ro16 Group C
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Borderlands 3 General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread The Big Programming Thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine UK Politics Mega-thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
Too Many LANs? Tournament Ov…
TrAiDoS
i'm really bored guys
Peanutsc
I <=> 9
KrillinFromwales
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1469 users

The Big Programming Thread - Page 850

Forum Index > General Forum
Post a Reply
Prev 1 848 849 850 851 852 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-21 22:33:43
February 21 2017 22:32 GMT
#16981
use clang instead of gcc or whichever compiler you're using

readable output is frigging amazing

gdb is not necessary, generally most of us just printf debug because it's a lot of effort to re-run gdb
however gdb is super nice to use once you're up to speed with it, using a debugger in general feels amazing versus print statement debugging

i had to use windbg at work and after a while it was very fun reading and setting up breakpoints at hex addresses
There is no one like you in the universe.
tofucake
Profile Blog Joined October 2009
Hyrule19091 Posts
February 21 2017 23:28 GMT
#16982
The Big (Travis CS Degree) Thread
Liquipediaasante sana squash banana
Hanh
Profile Joined June 2016
146 Posts
February 22 2017 00:04 GMT
#16983
windbg is the bomb!!
i am super biased as an ex windows kernel dev. :D
windbg is one of the few kernel debuggers.

Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 22 2017 01:13 GMT
#16984
I've gotta use gcc, just like I've gotta use c89, because that's what is on our school's server
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
February 22 2017 14:06 GMT
#16985
do you guys know, what kind of infrastructure - technologies is needed to have real time video talk in a mobile app?

I've done it using sinch, which is a 3rd party service. I just got an api key etc. and wrote code in android following their examples.

-------------------------

I was wondering what would I need if I wanted to do it without any 3rd party services. I have read up on webrtc, which sinch uses too. From what I vaguely understand, I need

- a signaling server,
- a TURN server,
- maybe plus a STUN server,
- client code which can talk to the signaling server.
- knowledge about the above, more than just reading their wikipedia pages

I guess these are the things provided by sinch out of the box.

anyone have knowledge on this? maybe there are alternatives to webrtc or an easier way I didn't see in my various google searches.
Age of Mythology forever!
Manit0u
Profile Blog Joined August 2004
Poland17350 Posts
February 22 2017 14:20 GMT
#16986
Today I've butchered materialize.css to no end. But I'm quite happy with the results:

[image loading]

[image loading]
Time is precious. Waste it wisely.
Acrofales
Profile Joined August 2010
Spain18055 Posts
Last Edited: 2017-02-22 19:17:27
February 22 2017 15:50 GMT
#16987
You know what, I can use any input anybody is willing to give on my Android problem.

I have an instrumented ebook reader app that can be opened in two different ways, one way is through another app that downloads the content directly from a server and then launches the reader. The other is by opening the ebook from the filesystem. The former works just fine. The latter works, but only for specific file managers. It works with Astro and with ES file managers. It doesn't work with the default Android file manager or with AND (this is obvioulsy not an exhaustive test).

Here is the relevant bit from the manifest:

<activity
android:name=".activities.IntentResolverActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="stateHidden|adjustPan"
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
android:exported="true"
android:screenOrientation="landscape" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.epub" />
<data android:mimeType="*/*"/>
</intent-filter>


It's not that it doesn't launch correctly, it's that the app doesn't even show up in the list of possible apps to open files of the relevant type (epubs). My bet is that it has something to do with the mime type and that the file managers for which this doesn't work do something magic with mime types. But I specifically say I don't care about mimetypes ("*/*") to avoid any problems, and I can't seem to find a mime type that does work (I don't even know what it could be other than octet-stream: an epub is essentially a zip file, and if I try mimetype application/zip it breaks for all filemanagers).

Tested in Android Marshmallow and Nougat, I don't know whether the same happens in Kitkat (insofar as I know, older Android didn't even have a built-in file manager).

E: and for extra credit, you can answer it on StackExchange (clicky)

E2: someone on stackexchange beat you guys to it. Apparently Android SUCKS. Different file managers generate different types of intents (scheme: file, and scheme: content) and you have to check for all of them. Who invents this crap?
plasmidghost
Profile Blog Joined April 2011
Belgium16168 Posts
February 22 2017 22:37 GMT
#16988
I'm trying to set up a client/server program in C and have everything compiling correctly but I can't get it to output correctly. It's supposed to have the client take in three strings and send them to the server, which checks to see if they're all lowercase characters. If not, output an invalid string message. If so, count the number of vowels, and send all results to the client. It looks correct to me but I don't get why it isn't working.
+ Show Spoiler [Server code] +
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct Server
{
int l[1]; // stores number of vowels
int m[1]; // stores number of vowels
int n[1]; // stores number of vowels
char charbuff1[6]; // buffer holds a character
char outchar1[7]; // server puts string here
char charbuff2[6]; // buffer holds a character
char outchar2[7]; // server puts string here
char charbuff3[6]; // buffer holds a character
char outchar3[7]; // server puts string here
}
inst;
main (void)
{
memset(inst.charbuff1,0,6);
memset(inst.outchar1,0,7);
memset(inst.charbuff2,0,6);
memset(inst.outchar2,0,7);
memset(inst.charbuff3,0,6);
memset(inst.outchar3,0,7);
struct Server;
int i;
int fda; // to read from client
int fdb; // to write to client

/* Create the fifos and open them */
if ((mkfifo("FIFO1",0666)<0 && errno != EEXIST))
{
perror("cant create FIFO1");
exit(-1);
}

if ((mkfifo("FIFO2",0666)<0 && errno != EEXIST))
{
perror("cant create FIFO2");
exit(-1);
}

if((fda=open("FIFO1", O_RDONLY))<0)
printf("cant open fifo to write");

if((fdb=open("FIFO2", O_WRONLY))<0)
printf("cant open fifo to read");

read(fda, &inst, sizeof(inst)); //read the struct from client


for( i = 0; i<6; i++) //for loop to write the first string from charbuff array to outchar array
{
inst.outchar1[i] = inst.charbuff1[i];
inst.outchar1[6] = 0;
}
printf("\nServer: first string is: %s", inst.outchar1);

inst.l[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set l to 9
{
inst.l[1] = 9;
break;
}
else if(inst.outchar1[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment l by 1
{
inst.l[1]++;
}
else //if a character is a lowercase consonant, do nothing
{
inst.l[1];
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.l[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.l[1]);
}

for( i = 0; i<6; i++) //for loop to write the second string from charbuff array to outchar array
{
inst.outchar2[i] = inst.charbuff2[i];
inst.outchar2[6] = 0;
}
printf("\nServer: second string is: %s", inst.outchar2);

inst.m[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set m to 9
{
inst.m[1] = 9;
break;
}
else if(inst.outchar2[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment m by 1
{
inst.m[1]++;
}
else //if a character is a lowercase consonant, do nothing
{
inst.m[1];
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.m[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.m[1]);
}

for( i = 0; i<6; i++) //for loop to write the third string from charbuff array to outchar array
{
inst.outchar3[i] = inst.charbuff3[i];
inst.outchar3[6] = 0;
}
printf("\nServer: third string is: %s", inst.outchar3);

inst.n[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set n to 9
{
inst.n[1] = 9;
break;
}
else if(inst.outchar3[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment n by 1
{
inst.n[1]++;
}
else
{
inst.n[1]; //if a character is a lowercase consonant, do nothing
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.n[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.n[1]);
}
write(fdb, &inst, sizeof(inst));
printf("\nServer: This says I am ready to close.\n ");

close(fda);
close(fdb);
unlink("FIFO1");
unlink("FIFO2");

return 0;
}

+ Show Spoiler [Client code] +
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct Client
{
int l[1]; // stores number of vowels
int m[1]; // stores number of vowels
int n[1]; // stores number of vowels
char charbuff1[6]; // buffer holds a character
char outchar1[7]; // server puts string here
char charbuff2[6]; // buffer holds a character
char outchar2[7]; // server puts string here
char charbuff3[6]; // buffer holds a character
char outchar3[7]; // server puts string here
}
inst;
main (void)
{
memset(inst.charbuff1,0,6);
memset(inst.outchar1,0,7);
memset(inst.charbuff2,0,6);
memset(inst.outchar2,0,7);
memset(inst.charbuff3,0,6);
memset(inst.outchar3,0,7);
int fda; // to write to server
int fdb; // to read response from server
struct Client;
int i;

if((fda=open("FIFO1", O_WRONLY))<0) //open fifo to write to server
printf("cant open fifo to write");

if((fdb=open("FIFO2", O_RDONLY))<0) //open fifo to read from server
printf("cant open fifo to read");

printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the first input
{
scanf("%c", &inst.charbuff1[i]);
}
printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the second input
{
scanf("%c", &inst.charbuff2[i]);
}
printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the third input
{
scanf("%c", &inst.charbuff3[i]);
}
write(fda, &inst, sizeof(inst)); //write results to the struct

printf("\nClient: Got the characters sent, now waiting for response ");
read(fdb, &inst, sizeof(inst)); //read results from server struct
printf("\nClient: received from server %s", inst.outchar1);
printf("\nClient: Was this a valid string? ");
if(inst.l[1] = 9) //check if first string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.l[1]);
}
printf("\nClient: The number of vowels in the string is: %d", inst.l[1]);

printf("\nClient: received from server %s", inst.outchar2);
printf("\nClient: Was this a valid string? ");
if(inst.m[1] = 9) //check if second string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.m[1]);
}
printf("\nClient: received from server %s", inst.outchar3);
printf("\nClient: Was this a valid string? ");
if(inst.n[1] = 9) //check if third string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.n[1]);
}

close(fda);
close(fdb);

printf ("\nall done!\n");

}
Yugoslavia will always live on in my heart
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-23 01:28:35
February 23 2017 01:25 GMT
#16989
On February 23 2017 07:37 plasmidghost wrote:
I'm trying to set up a client/server program in C and have everything compiling correctly but I can't get it to output correctly. It's supposed to have the client take in three strings and send them to the server, which checks to see if they're all lowercase characters. If not, output an invalid string message. If so, count the number of vowels, and send all results to the client. It looks correct to me but I don't get why it isn't working.
+ Show Spoiler [Server code] +
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct Server
{
int l[1]; // stores number of vowels
int m[1]; // stores number of vowels
int n[1]; // stores number of vowels
char charbuff1[6]; // buffer holds a character
char outchar1[7]; // server puts string here
char charbuff2[6]; // buffer holds a character
char outchar2[7]; // server puts string here
char charbuff3[6]; // buffer holds a character
char outchar3[7]; // server puts string here
}
inst;
main (void)
{
memset(inst.charbuff1,0,6);
memset(inst.outchar1,0,7);
memset(inst.charbuff2,0,6);
memset(inst.outchar2,0,7);
memset(inst.charbuff3,0,6);
memset(inst.outchar3,0,7);
struct Server;
int i;
int fda; // to read from client
int fdb; // to write to client

/* Create the fifos and open them */
if ((mkfifo("FIFO1",0666)<0 && errno != EEXIST))
{
perror("cant create FIFO1");
exit(-1);
}

if ((mkfifo("FIFO2",0666)<0 && errno != EEXIST))
{
perror("cant create FIFO2");
exit(-1);
}

if((fda=open("FIFO1", O_RDONLY))<0)
printf("cant open fifo to write");

if((fdb=open("FIFO2", O_WRONLY))<0)
printf("cant open fifo to read");

read(fda, &inst, sizeof(inst)); //read the struct from client


for( i = 0; i<6; i++) //for loop to write the first string from charbuff array to outchar array
{
inst.outchar1[i] = inst.charbuff1[i];
inst.outchar1[6] = 0;
}
printf("\nServer: first string is: %s", inst.outchar1);

inst.l[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set l to 9
{
inst.l[1] = 9;
break;
}
else if(inst.outchar1[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment l by 1
{
inst.l[1]++;
}
else //if a character is a lowercase consonant, do nothing
{
inst.l[1];
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.l[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.l[1];
}

for( i = 0; i<6; i++) //for loop to write the second string from charbuff array to outchar array
{
inst.outchar2[i] = inst.charbuff2[i];
inst.outchar2[6] = 0;
}
printf("\nServer: second string is: %s", inst.outchar2);

inst.m[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set m to 9
{
inst.m[1] = 9;
break;
}
else if(inst.outchar2[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment m by 1
{
inst.m[1]++;
}
else //if a character is a lowercase consonant, do nothing
{
inst.m[1];
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.m[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.m[1];
}

for( i = 0; i<6; i++) //for loop to write the third string from charbuff array to outchar array
{
inst.outchar3[i] = inst.charbuff3[i];
inst.outchar3[6] = 0;
}
printf("\nServer: third string is: %s", inst.outchar3);

inst.n[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set n to 9
{
inst.n[1] = 9;
break;
}
else if(inst.outchar3[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment n by 1
{
inst.n[1]++;
}
else
{
inst.n[1]; //if a character is a lowercase consonant, do nothing
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.n[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.n[1];
}
write(fdb, &inst, sizeof(inst));
printf("\nServer: This says I am ready to close.\n ");

close(fda);
close(fdb);
unlink("FIFO1");
unlink("FIFO2");

return 0;
}

+ Show Spoiler [Client code] +
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct Client
{
int l[1]; // stores number of vowels
int m[1]; // stores number of vowels
int n[1]; // stores number of vowels
char charbuff1[6]; // buffer holds a character
char outchar1[7]; // server puts string here
char charbuff2[6]; // buffer holds a character
char outchar2[7]; // server puts string here
char charbuff3[6]; // buffer holds a character
char outchar3[7]; // server puts string here
}
inst;
main (void)
{
memset(inst.charbuff1,0,6);
memset(inst.outchar1,0,7);
memset(inst.charbuff2,0,6);
memset(inst.outchar2,0,7);
memset(inst.charbuff3,0,6);
memset(inst.outchar3,0,7);
int fda; // to write to server
int fdb; // to read response from server
struct Client;
int i;

if((fda=open("FIFO1", O_WRONLY))<0) //open fifo to write to server
printf("cant open fifo to write");

if((fdb=open("FIFO2", O_RDONLY))<0) //open fifo to read from server
printf("cant open fifo to read");

printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the first input
{
scanf("%c", &inst.charbuff1[i];
}
printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the second input
{
scanf("%c", &inst.charbuff2[i];
}
printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the third input
{
scanf("%c", &inst.charbuff3[i];
}
write(fda, &inst, sizeof(inst)); //write results to the struct

printf("\nClient: Got the characters sent, now waiting for response ");
read(fdb, &inst, sizeof(inst)); //read results from server struct
printf("\nClient: received from server %s", inst.outchar1);
printf("\nClient: Was this a valid string? ");
if(inst.l[1] = 9) //check if first string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.l[1];
}
printf("\nClient: The number of vowels in the string is: %d", inst.l[1];

printf("\nClient: received from server %s", inst.outchar2);
printf("\nClient: Was this a valid string? ");
if(inst.m[1] = 9) //check if second string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.m[1];
}
printf("\nClient: received from server %s", inst.outchar3);
printf("\nClient: Was this a valid string? ");
if(inst.n[1] = 9) //check if third string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.n[1];
}

close(fda);
close(fdb);

printf ("\nall done!\n");

}


What's the error? Have you tested a minimal server client already? Otherwise this is just a blob of code that's hard to debug. Using functions makes your code clearer.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 23 2017 01:27 GMT
#16990
more discrete math

this homework wants me to prove √28 is irrational without using the fundamental theorem of arithmetic

at first the only way I could see was how I did it before with √7, which is to do the contrapositive, and do every case for
n=1 to n=6, but in this case I would have to do it with 1 to 27...

but then I realized √28 is 2 * √7

so really I am just solving the same question over again. But I am wondering if that's just an oversight on my professor's part

and I am wondering if there is some other (reasonable) way to solve this question? just throwing it out there if someone has some idea
plasmidghost
Profile Blog Joined April 2011
Belgium16168 Posts
Last Edited: 2017-02-23 01:30:23
February 23 2017 01:29 GMT
#16991
On February 23 2017 10:25 Blisse wrote:
Show nested quote +
On February 23 2017 07:37 plasmidghost wrote:
I'm trying to set up a client/server program in C and have everything compiling correctly but I can't get it to output correctly. It's supposed to have the client take in three strings and send them to the server, which checks to see if they're all lowercase characters. If not, output an invalid string message. If so, count the number of vowels, and send all results to the client. It looks correct to me but I don't get why it isn't working.
+ Show Spoiler [Server code] +
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct Server
{
int l[1]; // stores number of vowels
int m[1]; // stores number of vowels
int n[1]; // stores number of vowels
char charbuff1[6]; // buffer holds a character
char outchar1[7]; // server puts string here
char charbuff2[6]; // buffer holds a character
char outchar2[7]; // server puts string here
char charbuff3[6]; // buffer holds a character
char outchar3[7]; // server puts string here
}
inst;
main (void)
{
memset(inst.charbuff1,0,6);
memset(inst.outchar1,0,7);
memset(inst.charbuff2,0,6);
memset(inst.outchar2,0,7);
memset(inst.charbuff3,0,6);
memset(inst.outchar3,0,7);
struct Server;
int i;
int fda; // to read from client
int fdb; // to write to client

/* Create the fifos and open them */
if ((mkfifo("FIFO1",0666)<0 && errno != EEXIST))
{
perror("cant create FIFO1");
exit(-1);
}

if ((mkfifo("FIFO2",0666)<0 && errno != EEXIST))
{
perror("cant create FIFO2");
exit(-1);
}

if((fda=open("FIFO1", O_RDONLY))<0)
printf("cant open fifo to write");

if((fdb=open("FIFO2", O_WRONLY))<0)
printf("cant open fifo to read");

read(fda, &inst, sizeof(inst)); //read the struct from client


for( i = 0; i<6; i++) //for loop to write the first string from charbuff array to outchar array
{
inst.outchar1[i] = inst.charbuff1[i];
inst.outchar1[6] = 0;
}
printf("\nServer: first string is: %s", inst.outchar1);

inst.l[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set l to 9
{
inst.l[1] = 9;
break;
}
else if(inst.outchar1[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment l by 1
{
inst.l[1]++;
}
else //if a character is a lowercase consonant, do nothing
{
inst.l[1];
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.l[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.l[1];
}

for( i = 0; i<6; i++) //for loop to write the second string from charbuff array to outchar array
{
inst.outchar2[i] = inst.charbuff2[i];
inst.outchar2[6] = 0;
}
printf("\nServer: second string is: %s", inst.outchar2);

inst.m[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set m to 9
{
inst.m[1] = 9;
break;
}
else if(inst.outchar2[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment m by 1
{
inst.m[1]++;
}
else //if a character is a lowercase consonant, do nothing
{
inst.m[1];
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.m[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.m[1];
}

for( i = 0; i<6; i++) //for loop to write the third string from charbuff array to outchar array
{
inst.outchar3[i] = inst.charbuff3[i];
inst.outchar3[6] = 0;
}
printf("\nServer: third string is: %s", inst.outchar3);

inst.n[1] = 0;

for( i = 0; i<6; i++) //for loop to check for non-lowercase characters
{
if(inst.outchar1[i] < 'a' && inst.outchar1[i] > 'z') //if a character isn't lowercase, set n to 9
{
inst.n[1] = 9;
break;
}
else if(inst.outchar3[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment n by 1
{
inst.n[1]++;
}
else
{
inst.n[1]; //if a character is a lowercase consonant, do nothing
}
}
printf("\nServer: Checked for uppercase letters");

if(inst.n[1] = 9) //if an invalid character was encountered
{
printf("\nServer: There are uppercase letters");
}
else //if no invalid character was encountered
{
printf("\nServer: There are no uppercase letters");
printf("\nServer: The humber of vowels are: %d", inst.n[1];
}
write(fdb, &inst, sizeof(inst));
printf("\nServer: This says I am ready to close.\n ");

close(fda);
close(fdb);
unlink("FIFO1");
unlink("FIFO2");

return 0;
}

+ Show Spoiler [Client code] +
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

struct Client
{
int l[1]; // stores number of vowels
int m[1]; // stores number of vowels
int n[1]; // stores number of vowels
char charbuff1[6]; // buffer holds a character
char outchar1[7]; // server puts string here
char charbuff2[6]; // buffer holds a character
char outchar2[7]; // server puts string here
char charbuff3[6]; // buffer holds a character
char outchar3[7]; // server puts string here
}
inst;
main (void)
{
memset(inst.charbuff1,0,6);
memset(inst.outchar1,0,7);
memset(inst.charbuff2,0,6);
memset(inst.outchar2,0,7);
memset(inst.charbuff3,0,6);
memset(inst.outchar3,0,7);
int fda; // to write to server
int fdb; // to read response from server
struct Client;
int i;

if((fda=open("FIFO1", O_WRONLY))<0) //open fifo to write to server
printf("cant open fifo to write");

if((fdb=open("FIFO2", O_RDONLY))<0) //open fifo to read from server
printf("cant open fifo to read");

printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the first input
{
scanf("%c", &inst.charbuff1[i];
}
printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the second input
{
scanf("%c", &inst.charbuff2[i];
}
printf("Client: Please enter up to 6 lowercase characters: ");
for(i=0;i<6;i++) //for loop to take the third input
{
scanf("%c", &inst.charbuff3[i];
}
write(fda, &inst, sizeof(inst)); //write results to the struct

printf("\nClient: Got the characters sent, now waiting for response ");
read(fdb, &inst, sizeof(inst)); //read results from server struct
printf("\nClient: received from server %s", inst.outchar1);
printf("\nClient: Was this a valid string? ");
if(inst.l[1] = 9) //check if first string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.l[1];
}
printf("\nClient: The number of vowels in the string is: %d", inst.l[1];

printf("\nClient: received from server %s", inst.outchar2);
printf("\nClient: Was this a valid string? ");
if(inst.m[1] = 9) //check if second string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.m[1];
}
printf("\nClient: received from server %s", inst.outchar3);
printf("\nClient: Was this a valid string? ");
if(inst.n[1] = 9) //check if third string had an invalid character
{
printf("No");
}
else
{
printf("Yes");
printf("\nClient: The number of vowels in the string is: %d", inst.n[1];
}

close(fda);
close(fdb);

printf ("\nall done!\n");

}


What's the error? Have you tested a minimal server client already? Otherwise this is just a blob of code that's hard to debug.

I get the following output whenever I run the code:
[image loading]
I did try a stripped-down server and it worked fine
Yugoslavia will always live on in my heart
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-23 02:11:19
February 23 2017 01:46 GMT
#16992
For one, your scanf 6 times gets 6 letters, q, \n, w, \n, e, \n

Need scanf(" %c", ..) with the extra space

Secondly l, m and n are allocated as size 1 arrays for some erason, but you access the second element by l[1], which is invalid. l[0] is what you want, or really just not using an array type here.


Other nitpick, you declare struct Client and struct Server, but you use the instanced inst variable instead, which is like using globals (idk the proper name of it).


This also doesn't do what you want (always true)

else if(inst.outchar2[i] = 'a' || 'e' || 'i' || 'o' || 'u') //if a character is a vowel, increment m by 1


Neither does this (harmless)

else
{
inst.n[1]; //if a character is a lowercase consonant, do nothing
}

And neither does this (not so harmless)

if(inst.n[1] = 9) //if an invalid character was encountered
There is no one like you in the universe.
plasmidghost
Profile Blog Joined April 2011
Belgium16168 Posts
Last Edited: 2017-02-23 02:20:26
February 23 2017 01:57 GMT
#16993
On February 23 2017 10:46 Blisse wrote:
For one, your scanf 6 times gets 6 letters, q, \n, w, \n, e, \n

Need scanf(" %c", ..) with the extra space

Secondly l, m and n are allocated as size 1 arrays for some erason, but you access the second element by l[1], which is invalid. l[0] is what you want, or really just not using an array type here

With that specific output I was just testing to see if it would take enter keystrokes as characters
I replaced all the size one arrays to just be an int as well as changing my for loops for accepting characters to be fgets statements and it now partially works
[image loading]
Current server code: pastebin.com
Current client code: pastebin.com
Yugoslavia will always live on in my heart
Manit0u
Profile Blog Joined August 2004
Poland17350 Posts
Last Edited: 2017-02-23 02:49:37
February 23 2017 02:47 GMT
#16994
@plasmidghost:
Just some typical nitpicks of mine:
1. Improve your code formatting (read about One True Brace Style).
2. Do not use variable "l" (looks just like 1 and can be very confusing).
3. Do not name your variables charbuff1, charbuff2 and so on. It's very hard to debug such code (especially when you come back to it later). Programmer's intent should be clear at all times.
4. Do not name your variables "fda", "fdb" and so on. The same reason as above applies. Just call them write_only_fifo and read_only_fifo or something like that. Something like input_stream and output_stream could work too.
5. Put int in front of main.
6. Split your code into more specialized functions. Doing everything in main isn't very good or very readable (there's a reason why functions should be kept down to 20 lines max).
7. Use more structs. Having everything in one place is bad for you (separation of concerns).
Time is precious. Waste it wisely.
plasmidghost
Profile Blog Joined April 2011
Belgium16168 Posts
Last Edited: 2017-02-23 04:14:39
February 23 2017 04:14 GMT
#16995
Regarding my code, I've noticed a few things:
No matter the input, my variables to check for invalid characters/vowel number always goes to 9, meaning my if else statements in my server code are bad
The client only receives the string from the server if there are any uppercase letters
Yugoslavia will always live on in my heart
plasmidghost
Profile Blog Joined April 2011
Belgium16168 Posts
February 23 2017 05:14 GMT
#16996
(Hope this is allowed) I'll give someone an up to $10 Steam game of their choice if they can help me get my C programs working since it's not really fair of me to ask for someone to help me with code this complex for free
Yugoslavia will always live on in my heart
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
February 23 2017 06:07 GMT
#16997
Today I found out that if you are local hosting something it is apparently visible to everyone on your LAN, which is very exciting news for me! My friend came over and I taught him some programming for a few hours and he asked a fair number of questions that had never crossed my mind. That was one of them.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
February 23 2017 06:37 GMT
#16998
--- Nuked ---
Acrofales
Profile Joined August 2010
Spain18055 Posts
February 23 2017 06:59 GMT
#16999
On February 23 2017 10:27 travis wrote:
more discrete math

this homework wants me to prove √28 is irrational without using the fundamental theorem of arithmetic

at first the only way I could see was how I did it before with √7, which is to do the contrapositive, and do every case for
n=1 to n=6, but in this case I would have to do it with 1 to 27...

but then I realized √28 is 2 * √7

so really I am just solving the same question over again. But I am wondering if that's just an oversight on my professor's part

and I am wondering if there is some other (reasonable) way to solve this question? just throwing it out there if someone has some idea

Not sure how you proved it for sqrt(7), but if you already did it, then yes, you're done. You just have to show that multiplying an irrational number by a rational number will give an irrational number.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
February 23 2017 07:27 GMT
#17000
On February 23 2017 13:14 plasmidghost wrote:
Regarding my code, I've noticed a few things:
No matter the input, my variables to check for invalid characters/vowel number always goes to 9, meaning my if else statements in my server code are bad
The client only receives the string from the server if there are any uppercase letters


idk if you read my editted comment but there are a few errors

you do = 9 instead of == 9 which sets the value instead of comparing them

you do c == 'a' || 'e' || 'i' which checks if char is equal to 'a', then if 'e' > 0 which is true, and if 'i' > 0 which is true, and etc.


you should really use functions to eliminate duplicate code

bool is_vowel(char c) {
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
There is no one like you in the universe.
Prev 1 848 849 850 851 852 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
21:00
OSC Elite Rising Star #16
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft590
RuFF_SC2 186
Nathanias 113
Nina 13
StarCraft: Brood War
Movie 590
Icarus 9
League of Legends
JimRising 634
Counter-Strike
Stewie2K374
Super Smash Bros
hungrybox649
Heroes of the Storm
Khaldor123
Other Games
summit1g9066
XaKoH 154
NeuroSwarm138
ViBE87
Organizations
Other Games
gamesdonequick425
BasetradeTV6
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH253
• practicex 20
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 57
• Diggity2
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Scarra753
Upcoming Events
BSL Open LAN 2025 - War…
3h 43m
RSL Revival
5h 43m
Classic vs TBD
WardiTV Invitational
6h 43m
Online Event
11h 43m
Afreeca Starleague
1d 5h
Barracks vs Mini
Wardi Open
1d 6h
Monday Night Weeklies
1d 11h
Sparkling Tuna Cup
2 days
LiuLi Cup
3 days
The PondCast
4 days
[ Show More ]
CranKy Ducklings
5 days
Maestros of the Game
6 days
Clem vs Reynor
[BSL 2025] Weekly
6 days
[BSL 2025] Weekly
6 days
Liquipedia Results

Completed

Proleague 2025-09-18
Chzzk MurlocKing SC1 vs SC2 Cup #2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
2025 Chongqing Offline CUP
BSL World Championship of Poland 2025
RSL Revival: Season 2
Maestros of the Game
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1

Upcoming

IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.